blob: d6feec6f1523e665db435b020f3e6630b6d0acff [file] [log] [blame]
Teng Liang938be582015-07-15 16:25:26 -07001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2014 Regents of the University of California.
4# Author: Teng Liang <philoliang2011@gmail.com>
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Lesser General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18# A copy of the GNU General Public License is in the file COPYING.
19
20"""
21This module defines the DeviceProfile class with holds descriptors of device
22"""
23
Weiweifea2f192015-07-21 17:06:44 -070024class DeviceProfile(object):
25
26 def __init__(self, prefix = None, location = None, manufacturer = None, category = None, type_ = None, model = None, serialNumber = None, serviceProfileList = None):
27 '''initialize device profile.'''
28 self._prefix = prefix
29 self._location = location
30 self._manufacturer = manufacturer
31 self._category = category
32 self._type = type_
33 self._model = model
34 self._serialNumber = serialNumber
35 if serviceProfileList is None:
36 self._serviceProfileList = []
37 else:
38 self._serviceProfileList = serviceProfileList
39 self._metadata = ['prefix', 'location', 'manufacturer', 'category', 'type', 'model', 'serialNumber', 'serviceProfileList']
40
41 def __str__(self):
42 info ='prefix: '+ self._prefix + '\nlocation: '+ self._location + '\nmanufacturer: ' + self._manufacturer + '\ncategory: ' + self._category + '\ntype: ' + self._type + '\nserial number: ' + self._serialNumber + '\nservice profile list: '
43 info += ', '.join(self._serviceProfileList)
44 info += '\nmetadata: '
45 info += ', '.join(self._metadata)
46 return info
47
48 def getPrefix(self):
49 '''get device prefix from profile'''
50 return self._prefix
51
52 def getLocation(self):
53 '''get device location from profile'''
54 return self._location
55
56 def getManufacturer(self):
57 '''get device manufacturer from profile'''
58 return self._manufacturer
59
60 def getCategory(self):
61 '''get device category from profile'''
62 return self._category
63
64 def getType(self):
65 '''get device type from profile'''
66 return self._type
67
68 def getModel(self):
69 '''get device model from profile'''
70 return self._model
71
72 def getSerialNumber(self):
73 '''get device serial number from profile'''
74 return self._serialNumber
75
76 def getServiceProfileList(self):
77 '''get the service profile list that the device support'''
78 return self._serviceProfileList
79
80 def getMetadata(self):
81 '''get metadata from profile'''
82 return self._metadata
83
84 def setPrefix(self, prefix):
85 '''set device prefix from profile'''
86 self._prefix = prefix
87
88 def setLocation(self, location):
89 '''set device location from profile'''
90 self._location = location
91
92 def setManufacturer(self, manufacturer):
93 '''set device manufacturer from profile'''
94 self._manufacturer = manufacturer
95
96 def setCategory(self, category):
97 '''set device category from profile'''
98 self._category = category
99
100 def setType(self, type_):
101 '''set device type from profile'''
102 self._type = type_
103
104 def setModel(self, model):
105 '''set device model from profile'''
106 self._model = model
107
108 def setSerialNumber(self, serialNumber):
109 '''set device serial number from profile'''
110 self._serialNumber = serialNumber
111
112 def setServiceProfile(self, serviceProfileList):
113 '''set the service profile list that the device support'''
114 self._serviceProfileList = serviceProfileList
115
116 def addServiceProfile(self, newServiceProfile):
117 '''
118 add one or several service profiles to the service profile list.
119 :param str/list _serviceProfile: a service profile or several profiles in the form of a list
120 '''
121 if isinstance(newServiceProfile, str):
122 self._serviceProfileList.append(newServiceProfile)
123 elif type(newServiceProfile) is list:
124 self._serviceProfileList += newServiceProfile
125
126 def addMetadata(self, newMetadata):
127 '''
128 add device one or several attributes to metadata.
129 :param str/list _newMetadata: new attributes to be added
130 '''
131 if isinstance(newMetadata, str):
132 self._metadata.append(newMetadata)
133 elif type(newMetadata) is list:
134 self._metadata += newMetadata