blob: 966886fa88f2f823ad32389c2bdf1ad36ed609cd [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"""
Weiweie5640c62015-07-31 01:43:01 -070023from pyndn import Name
Teng Liang938be582015-07-15 16:25:26 -070024
Weiweifea2f192015-07-21 17:06:44 -070025class DeviceProfile(object):
26
27 def __init__(self, prefix = None, location = None, manufacturer = None, category = None, type_ = None, model = None, serialNumber = None, serviceProfileList = None):
Weiweie5640c62015-07-31 01:43:01 -070028 '''initialize device profile.
29 param Name prefix: device's prefix
30 param str location: device's location
31 param str manufacturer: device's manufacturer
32 param str category: device's category
33 param str type: device's type
34 param str model: device's model
35 parma str lsit serviceProfileList: the list of service profile names
36 '''
Weiweifea2f192015-07-21 17:06:44 -070037 self._prefix = prefix
38 self._location = location
39 self._manufacturer = manufacturer
40 self._category = category
41 self._type = type_
42 self._model = model
43 self._serialNumber = serialNumber
44 if serviceProfileList is None:
45 self._serviceProfileList = []
46 else:
47 self._serviceProfileList = serviceProfileList
48 self._metadata = ['prefix', 'location', 'manufacturer', 'category', 'type', 'model', 'serialNumber', 'serviceProfileList']
49
50 def __str__(self):
Weiweie5640c62015-07-31 01:43:01 -070051 info ='prefix: '+ self._prefix.toUri() + '\nlocation: '+ str(self._location) + '\nmanufacturer: ' + str(self._manufacturer) + '\ncategory: ' + str(self._category) + '\ntype: ' + str(self._type) + '\nserial number: ' + str(self._serialNumber) + '\nservice profile list: '
Weiweifea2f192015-07-21 17:06:44 -070052 info += ', '.join(self._serviceProfileList)
53 info += '\nmetadata: '
54 info += ', '.join(self._metadata)
55 return info
56
57 def getPrefix(self):
58 '''get device prefix from profile'''
59 return self._prefix
60
61 def getLocation(self):
62 '''get device location from profile'''
63 return self._location
64
65 def getManufacturer(self):
66 '''get device manufacturer from profile'''
67 return self._manufacturer
68
69 def getCategory(self):
70 '''get device category from profile'''
71 return self._category
72
73 def getType(self):
74 '''get device type from profile'''
75 return self._type
76
77 def getModel(self):
78 '''get device model from profile'''
79 return self._model
80
81 def getSerialNumber(self):
82 '''get device serial number from profile'''
83 return self._serialNumber
84
85 def getServiceProfileList(self):
86 '''get the service profile list that the device support'''
87 return self._serviceProfileList
88
89 def getMetadata(self):
90 '''get metadata from profile'''
91 return self._metadata
92
93 def setPrefix(self, prefix):
94 '''set device prefix from profile'''
95 self._prefix = prefix
96
97 def setLocation(self, location):
98 '''set device location from profile'''
99 self._location = location
100
101 def setManufacturer(self, manufacturer):
102 '''set device manufacturer from profile'''
103 self._manufacturer = manufacturer
104
105 def setCategory(self, category):
106 '''set device category from profile'''
107 self._category = category
108
109 def setType(self, type_):
110 '''set device type from profile'''
111 self._type = type_
112
113 def setModel(self, model):
114 '''set device model from profile'''
115 self._model = model
116
117 def setSerialNumber(self, serialNumber):
118 '''set device serial number from profile'''
119 self._serialNumber = serialNumber
120
121 def setServiceProfile(self, serviceProfileList):
122 '''set the service profile list that the device support'''
123 self._serviceProfileList = serviceProfileList
124
125 def addServiceProfile(self, newServiceProfile):
126 '''
127 add one or several service profiles to the service profile list.
128 :param str/list _serviceProfile: a service profile or several profiles in the form of a list
129 '''
130 if isinstance(newServiceProfile, str):
131 self._serviceProfileList.append(newServiceProfile)
132 elif type(newServiceProfile) is list:
133 self._serviceProfileList += newServiceProfile
134
135 def addMetadata(self, newMetadata):
136 '''
137 add device one or several attributes to metadata.
138 :param str/list _newMetadata: new attributes to be added
139 '''
140 if isinstance(newMetadata, str):
141 self._metadata.append(newMetadata)
142 elif type(newMetadata) is list:
143 self._metadata += newMetadata