def AnswerCall(self): with Logger(__name__ + '.AnswerCall') as log: ofono_manager = dbus.Interface( self._bus.get_object('org.ofono', '/'), 'org.ofono.Manager') modems = ofono_manager.GetModems() for path, properties in modems: log.debug('modem path: %s' % (path)) if ('org.ofono.VoiceCallManager' not in properties['Interfaces']): continue vcm = dbus.Interface(self._bus.get_object('org.ofono', path), 'org.ofono.VoiceCallManager') calls = vcm.GetCalls() for path, properties in calls: state = properties['State'] log.debug('path: %s, state: %s' % (path, state)) if state != 'incoming': continue call = dbus.Interface( self._bus.get_object('org.ofono', path), 'org.ofono.VoiceCall') call.Answer()
def _linphone_worker(self): with Logger(__name__ + '._linphone_worker') as log: register_command = "register %s %s %s\n" % ( self._identity, self._proxy, self._password) self._linphonec.stdin.write(register_command) self._linphonec.stdin.flush() while self._linphonec.poll() is None: message = self._linphonec.stdout.readline() log.debug('Linphonec: ' + message) if (message.find('Receiving new incoming call') >= 0): self.IncomingCall() if (message.find('Call terminated.') >= 0): self.Release() if (message.endswith('busy.\n')): self.Busy() if (message.startswith('linphonec> Registration')): if (message.endswith('successful.\n')): self.register() else: self.unregister() log.error('Registration at remote sip server failed')
def SendDtmf(self, digit): with Logger(__name__ + '.SendDtmf') as log: log.debug('Dbus: Get ofono manager') ofono_manager = dbus.Interface( self._bus.get_object('org.ofono', '/'), 'org.ofono.Manager') log.debug('Dbus: Get modem path') modems = ofono_manager.GetModems() # find modem with active call # why is SendTones a method of VoiceCallManager and not VoiceCall??? for path, properties in modems: log.debug('modem path: %s' % (path)) if ('org.ofono.VoiceCallManager' not in properties['Interfaces']): continue vcm = dbus.Interface(self._bus.get_object('org.ofono', path), 'org.ofono.VoiceCallManager') calls = vcm.GetCalls() for path, properties in calls: state = properties['State'] log.debug('path: %s, state: %s' % (path, state)) if state != 'active': continue log.debug('Dbus: Send tone ...') vcm.SendTones(str(digit)) log.debug('Dbus: Tone sent.')
def register(self): with Logger(__name__ + '.register'): if (self._is_registered == False): bus = dbus.SystemBus() state_machine = dbus.Interface( bus.get_object('net.longexposure.potsbliz', '/StateMachine'), 'net.longexposure.potsbliz.statemachine') state_machine.Register() self._is_registered = True
def __init__(self, service_name): with Logger(__name__ + '.__init__') as log: self._service_name = service_name dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) busName = dbus.service.BusName(service_name, bus=dbus.SystemBus()) dbus.service.Object.__init__(self, busName, '/Userpart') self._is_registered = False
def run(self): with Logger(__name__ + '.run'): loop = gobject.MainLoop() gobject.threads_init() dbus.mainloop.glib.threads_init() # register for SIGTERM signal.signal(signal.SIGTERM, lambda signum, frame: loop.quit()) # start main loop loop.run()
def _property_changed(self, name, value, path, interface): with Logger(__name__ + '._property_changed') as log: log.debug("{%s} [%s] %s" % ( interface, name, str(value), )) if ((interface == 'org.ofono.Modem') and (name == 'Online')): if (value == 1): # if we invoke update_registration here, often no online modem is found!?! self.register() else: self._update_registration()
def convert(number): with Logger(__name__ + '.convert') as log: # read speeddial numbers from config speeddial_numbers = config.list_speeddial_numbers() for entry in speeddial_numbers: if (entry['shortcut'] == number): # remove non-digit characters expanded_number = re.sub('[^0-9]+', '', entry['phonenumber']) log.debug('Speeddial number found: ' + number + ' => ' + expanded_number) return expanded_number # no speeddial number found return number
def __init__(self, identity, proxy, password, port=5060, call_pattern='.*'): with Logger(__name__ + '.__init__') as log: super(Ipup, self).__init__('net.longexposure.potsbliz.ipup.port' + str(port)) # call base class constructor self._identity = identity self._proxy = proxy self._password = password self._port = port self._call_pattern = call_pattern
def __enter__(self): with Logger(__name__ + '.__enter__'): # write linphonec config file config_file = '/var/tmp/.linphonerc-' + self._identity with open(config_file, 'w') as file: file.write("[sip]\n") file.write("sip_port=%d\n" % self._port) self._linphonec = Popen(['/usr/bin/linphonec', '-c', config_file], stdout=PIPE, stdin=PIPE) self._worker_thread = Thread(target=self._linphone_worker) self._worker_thread.start() return self
def _update_registration(self): with Logger(__name__ + '._update_registration') as log: ofono_manager = dbus.Interface( self._bus.get_object('org.ofono', '/'), 'org.ofono.Manager') modems = ofono_manager.GetModems() for path, properties in modems: if ('org.ofono.VoiceCallManager' not in properties['Interfaces']): continue if (properties['Online'] == False): continue # at least one modem is online, ==> register self.register() return # no online modem found, ==> unregister self.unregister()
def run(self): with Logger(__name__ + '.run') as log: log.info('Starting POTSBLIZ ...') dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) with StateMachine(): self._loop = gobject.MainLoop() gobject.threads_init() dbus.mainloop.glib.threads_init() # register for SIGTERM signal.signal(signal.SIGTERM, lambda signum, frame: self._loop.quit()) self._loop.run() log.info('SIGTERM event received. Shutting down ...')
def MakeCall(self, called_number): with Logger(__name__ + '.MakeCall') as log: ofono_manager = dbus.Interface( self._bus.get_object('org.ofono', '/'), 'org.ofono.Manager') modems = ofono_manager.GetModems() for path, properties in modems: log.debug('modem path: %s' % (path)) if ('org.ofono.VoiceCallManager' not in properties['Interfaces']): continue if (properties['Online'] == False): continue vcm = dbus.Interface(self._bus.get_object('org.ofono', path), 'org.ofono.VoiceCallManager') dial_path = vcm.Dial(called_number, 'default') log.debug(dial_path) return raise Exception('No active modem found')
def TerminateCall(self): with Logger(__name__ + '.TerminateCall') as log: ofono_manager = dbus.Interface( self._bus.get_object('org.ofono', '/'), 'org.ofono.Manager') modems = ofono_manager.GetModems() for path, properties in modems: log.debug('modem path: %s' % (path)) if ('org.ofono.VoiceCallManager' not in properties['Interfaces']): continue vcm = dbus.Interface(self._bus.get_object('org.ofono', path), 'org.ofono.VoiceCallManager') calls = vcm.GetCalls() for path, properties in calls: call = dbus.Interface( self._bus.get_object('org.ofono', path), 'org.ofono.VoiceCall') call.Hangup()
def __enter__(self): with Logger(__name__ + '.__enter__'): self._bus = dbus.SystemBus() subprocess.Popen(["pulseaudio", "-D"]) self._bus.add_signal_receiver(self._property_changed, bus_name="org.ofono", signal_name="PropertyChanged", path_keyword="path", interface_keyword="interface") self._bus.add_signal_receiver(self._call_added, bus_name="org.ofono", signal_name="CallAdded") self._bus.add_signal_receiver(self._call_removed, bus_name="org.ofono", signal_name="CallRemoved") self._update_registration() return self
# POTSBLIZ - Plain Old Telephone Service Beyond Local IP Stack # (C)2015 - Norbert Huffschmid - GNU GPL V3 # BTUP - Bluetooth User Part from potsbliz.logger import Logger from potsbliz.userpart.bluetooth.btup import Btup from time import sleep if __name__ == '__main__': with Logger('Bluetooth::__main__') as log: # bluetooth disturbs sip audio when started simultanously log.info('Delayed start of Bluetooth userpart. Waiting ...') sleep(15) log.info('Bluetooth userpart for POTSBLIZ started ...') with Btup() as userpart: userpart.run() log.info('Bluetooth userpart for POTSBLIZ terminated')
# Rotary Dial plugin for POTSBLIZ # (C)2015 - Norbert Huffschmid - GNU GPL V3 import dbus.mainloop.glib import gobject import signal from potsbliz.logger import Logger from potsbliz.plugin.rotary.rotary import Anip if __name__ == '__main__': with Logger('rotary::__main__') as log: log.info('Starting rotary dial plugin for POTSBLIZ ...') dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) loop = gobject.MainLoop() gobject.threads_init() dbus.mainloop.glib.threads_init() # register for SIGTERM signal.signal(signal.SIGTERM, lambda signum, frame: loop.quit()) with Anip(): loop.run()
def __exit__(self, type, value, traceback): with Logger(__name__ + '.__exit__'): self._linphonec.stdin.write("quit\n") self._worker_thread.join() self.unregister()
def CanCall(self, called_number): with Logger(__name__ + '.CanCall'): return (re.match('^[0-9][0-9#\*]+$', called_number) != None)
def __exit__(self, type, value, traceback): with Logger(__name__ + '.__exit__'): subprocess.Popen(["pulseaudio", "--kill"]) self.unregister()
def _call_removed(self, name): with Logger(__name__ + '._call_removed'): self.Release()
def CanCall(self, called_number): with Logger(__name__ + '.CanCall'): if (self._is_registered): return (re.match(self._call_pattern, called_number) != None) else: return False
def _call_added(self, name, value): with Logger(__name__ + '._call_added'): if (value['State'] == 'incoming'): self.IncomingCall()
def MakeCall(self, called_number): with Logger(__name__ + '.MakeCall'): sip_provider = self._identity.split('@')[1] destination = 'sip:' + called_number + '@' + sip_provider self._linphonec.stdin.write('call ' + destination + '\n')
def AnswerCall(self): with Logger(__name__ + '.AnswerCall'): self._linphonec.stdin.write('answer\n')
# POTSBLIZ - Plain Old Telephone Service Beyond Local IP Stack # (C)2015 - Norbert Huffschmid - GNU GPL V3 # Asterisk IP User Part from time import sleep from potsbliz.logger import Logger from potsbliz.userpart.sip.ipup import Ipup if __name__ == '__main__': with Logger('Asterisk::__main__') as log: log.info('Asterisk IP userpart for POTSBLIZ started ...') with Ipup( 'sip:potsbliz@localhost:5065', 'sip:localhost:5065', 'potsbliz', 5061, '^#$' # Asterisk only deals with '#' (hookflash) number ) as userpart: # wait for registration to be completed while (not userpart.CanCall('#')): sleep(1) # tell about IP address userpart.MakeCall('#') userpart.run()
def SendDtmf(self, digit): with Logger(__name__ + '.SendDtmf'): self._linphonec.stdin.write(digit + '\n')
def TerminateCall(self): with Logger(__name__ + '.TerminateCall'): self._linphonec.stdin.write('terminate\n')
# POTSBLIZ - Plain Old Telephone Service Beyond Local IP Stack # (C)2015 - Norbert Huffschmid - GNU GPL V3 # SIP IP User Part import potsbliz.config as config from potsbliz.logger import Logger from potsbliz.userpart.sip.ipup import Ipup if __name__ == '__main__': with Logger('SIP::__main__') as log: log.info('SIP IP userpart for POTSBLIZ started ...') sip_account = config.list_sip_accounts()[0] with Ipup(sip_account['identity'], sip_account['proxy'], sip_account['password'], 5060, '^[0-9][0-9#\*]+$') as userpart: userpart.run() log.info('SIP userpart for POTSBLIZ terminated')
def __init__(self): with Logger(__name__ + '.__init__') as log: super(Btup, self).__init__('net.longexposure.potsbliz.btup' ) # call base class constructor