def Modem3GPPProperties(self): """Return the 3GPP Properties of the modem object.""" return { 'Imei': self.imei, mm1.MM_MODEM3GPP_PROPERTY_REGISTRATION_STATE: UInt32(self.registration_state), 'OperatorCode': self.operator_code, 'OperatorName': self.operator_name, 'EnabledFacilityLocks': UInt32(0) }
def _message_received(self, msg): self.__message_received_id += 1 header = Dictionary({ 'pending-message-id': UInt32(self.__message_received_id), 'message-received': UInt64(time()), 'message-sender': UInt32(self.handle), 'message-type': UInt32(CHANNEL_TEXT_MESSAGE_TYPE_NORMAL), 'sender-nickname': String(self.handle.get_name()), }, signature='sv') body = Dictionary({ String('content-type'): String('text/plain'), String('content'): String(msg), }, signature='sv') message = Array([header, body], signature='a{sv}') self.MessageReceived(message)
class FooProtocol(Protocol, ProtocolInterfacePresence, ProtocolInterfaceAvatars): _proto = PROTOCOL _english_name = PROTOCOL.capitalize() _icon = "im-%s" % PROTOCOL _vcard_field = "im-%s" % PROTOCOL _mandatory_parameters = { 'account': 's', } _requestable_channel_classes = [ ( { CHANNEL + '.ChannelType': String(CHANNEL_TYPE_TEXT), CHANNEL + '.TargetHandleType': UInt32(HANDLE_TYPE_CONTACT), }, [ CHANNEL + '.TargetHandle', CHANNEL + '.TargetID', ] ), ] _supported_interfaces = [ CONNECTION_INTERFACE_ALIASING, CONNECTION_INTERFACE_AVATARS, CONNECTION_INTERFACE_BALANCE, CONNECTION_INTERFACE_CONTACT_GROUPS, CONNECTION_INTERFACE_CONTACT_INFO, CONNECTION_INTERFACE_CONTACT_LIST, CONNECTION_INTERFACE_CONTACTS, CONNECTION_INTERFACE_REQUESTS, CONNECTION_INTERFACE_SIMPLE_PRESENCE, ] _statuses = { CONNECTION_PRESENCE_STATUS_AVAILABLE: ( CONNECTION_PRESENCE_TYPE_AVAILABLE, True, True, ), CONNECTION_PRESENCE_STATUS_OFFLINE: ( CONNECTION_PRESENCE_TYPE_OFFLINE, True, False, ), } _supported_avatar_mime_types = [AVATAR_MIME] def __init__(self, connection_manager): Protocol.__init__(self, connection_manager, PROTOCOL) ProtocolInterfaceAvatars.__init__(self) ProtocolInterfacePresence.__init__(self) def create_connection(self, connection_manager, parameters): return FooConnection(self, connection_manager, parameters)
def ChangeState(self, new_state, why=mm1.MM_MODEM_STATE_CHANGE_REASON_UNKNOWN): logging.info('Change state from %s to %s', self.state, new_state) self.StateChanged(Int32(self.state), Int32(new_state), UInt32(why)) self.PropertiesChanged(mm1.MODEM_INTERFACE, {mm1.MM_MODEM_PROPERTY_STATE: Int32(new_state)}, []) self.state = new_state
def _send_message(self, message, flags, token): headers = Dictionary({ String('message-sent'): UInt64(time()), String('message-type'): UInt32(CHANNEL_TEXT_MESSAGE_TYPE_NORMAL), }, signature='sv') body = Dictionary({ String('content-type'): String('text/plain'), String('content'): message[1]['content'], }, signature='sv') message = Array([headers, body], signature='a{sv}') self.MessageSent(message, flags, String(token)) gobject.timeout_add(50, self._message_received, str(message[1]['content']))
def ChangeRegistrationState(self, new_state): """Updates the registration state of the modem. Updates the registration state of the modem and broadcasts a DBUS signal. Args: new_state: the new registation state of the modem. """ if new_state != self.registration_state: self.registration_state = new_state self.PropertiesChanged(mm1.MODEM_MODEM3GPP_INTERFACE, { mm1.MM_MODEM3GPP_PROPERTY_REGISTRATION_STATE: UInt32(new_state) }, [])
def GetStatus(self, *args, **kwargs): """Gets the general modem status. Returns: A dictionary of properties. """ logging.info('Modem: GetStatus') properties = { 'state': UInt32(self.state), 'signal-quality': UInt32(99), 'bands': self.carrier, 'access-technology': UInt32(0), 'm3gpp-registration-state': UInt32(self.registration_state), 'm3gpp-operator-code': '123', 'm3gpp-operator-name': '123', 'cdma-cdma1x-registration-state': UInt32(99), 'cdma-evdo-registration-state': UInt32(99), 'cdma-sid': '123', 'cdma-nid': '123', } if self.state >= mm1.MM_MODEM_STATE_ENABLED: properties['carrier'] = 'Test Network' return properties
def _avatar_retrieved(self, handle_id): handle = self.handle(HANDLE_TYPE_CONTACT, handle_id) self.AvatarRetrieved(UInt32(handle_id), String(handle.name), AVATAR, AVATAR_MIME)
def ModemProperties(self): """Return the properties of the modem object.""" properties = { # 'Sim': type='o' 'ModemCapabilities': UInt32(0), 'CurrentCapabilities': UInt32(0), 'MaxBearers': UInt32(2), 'MaxActiveBearers': UInt32(2), 'Manufacturer': 'Foo Electronics', 'Model': 'Super Foo Modem', 'Revision': '1.0', 'DeviceIdentifier': '123456789', 'Device': self.device, 'Driver': 'fake', 'Plugin': 'Foo Plugin', 'EquipmentIdentifier': self.meid, 'UnlockRequired': UInt32(0), #'UnlockRetries' type='a{uu}' mm1.MM_MODEM_PROPERTY_STATE: Int32(self.state), 'AccessTechnologies': UInt32(self.state), 'SignalQuality': Struct([UInt32(90), True], signature='ub'), 'OwnNumbers': ['6175551212'], 'SupportedModes': UInt32(0), 'AllowedModes': UInt32(0), 'PreferredMode': UInt32(0), 'SupportedBands': [UInt32(0)], 'Bands': [UInt32(0)] } if self.sim: properties['Sim'] = ObjectPath(self.sim.path) return properties