Example #1
0
 def _EH_CallFunctionEvent(self, event):
     try:
         event.function(*event.args, **event.kw)
     except:
         log.exception(
             'Exception occurred while calling %r in the %r thread' %
             (event.function, current_thread().name))
Example #2
0
    def delete(self):
        """
        Remove this object from the persistent configuration.
        """
        if self.__id__ is self.__class__.__id__:
            raise TypeError("cannot delete %s instance with default id" %
                            self.__class__.__name__)
        if self.__state__ == 'deleted':
            return
        self.__state__ = 'deleted'

        configuration = ConfigurationManager()
        notification_center = NotificationCenter()
        configuration.delete(
            self.__oldkey__)  # we need the key that wasn't yet saved
        notification_center.post_notification('CFGSettingsObjectWasDeleted',
                                              sender=self)
        try:
            configuration.save()
        except Exception as e:
            log.exception()
            notification_center.post_notification('CFGManagerSaveFailed',
                                                  sender=configuration,
                                                  data=NotificationData(
                                                      object=self,
                                                      operation='delete',
                                                      exception=e))
Example #3
0
 def _CH_process_results(self, command):
     for file in (f for f in command.files if not f.closed):
         try:
             _bonjour.DNSServiceProcessResult(file.file)
         except:
             # Should we close the file? The documentation doesn't say anything about this. -Luci
             log.exception()
     for file in command.files:
         file.active = False
     self._files = [f for f in self._files if not f.closed]
     self._select_proc.kill(RestartSelect)
Example #4
0
 def run(self):
     self.notification_center.post_notification('SIPEngineWillStart',
                                                sender=self)
     init_options = Engine.default_start_options.copy()
     init_options.update(self._options)
     try:
         self._ua = PJSIPUA(self._handle_event, **init_options)
     except Exception:
         log.exception('Exception occurred while starting the Engine')
         exc_type, exc_val, exc_tb = sys.exc_info()
         exc_tb = "".join(
             traceback.format_exception(exc_type, exc_val, exc_tb))
         self.notification_center.post_notification('SIPEngineGotException',
                                                    sender=self,
                                                    data=NotificationData(
                                                        type=exc_type,
                                                        value=exc_val,
                                                        traceback=exc_tb))
         self.notification_center.post_notification('SIPEngineDidFail',
                                                    sender=self)
         return
     else:
         self.notification_center.post_notification('SIPEngineDidStart',
                                                    sender=self)
     failed = False
     while not self._thread_stopping:
         try:
             failed = self._ua.poll()
         except:
             log.exception('Exception occurred while running the Engine')
             exc_type, exc_val, exc_tb = sys.exc_info()
             self.notification_center.post_notification(
                 'SIPEngineGotException',
                 sender=self,
                 data=NotificationData(type=exc_type,
                                       value=exc_val,
                                       traceback="".join(
                                           traceback.format_exception(
                                               exc_type, exc_val, exc_tb))))
             failed = True
         if failed:
             self.notification_center.post_notification('SIPEngineDidFail',
                                                        sender=self)
             break
     if not failed:
         self.notification_center.post_notification('SIPEngineWillEnd',
                                                    sender=self)
     self._ua.dealloc()
     del self._ua
     self.notification_center.post_notification('SIPEngineDidEnd',
                                                sender=self)
Example #5
0
    def save(self):
        """
        Use the ConfigurationManager to store the object under its id in the
        specified group or top-level otherwise, depending on whether group is
        None.

        This method will also post a CFGSettingsObjectDidChange notification,
        regardless of whether the settings have been saved to persistent storage
        or not. If the save does fail, a CFGManagerSaveFailed notification is
        posted as well.
        """

        if self.__state__ == 'deleted':
            return

        configuration = ConfigurationManager()
        notification_center = NotificationCenter()

        oldkey = self.__oldkey__ # save this here as get_modified will reset it

        modified_id = self.__class__.__id__.get_modified(self) if isinstance(self.__class__.__id__, SettingsObjectID) else None
        modified_settings = self.get_modified()

        if not modified_id and not modified_settings and self.__state__ != 'new':
            return

        if self.__state__ == 'new':
            configuration.update(self.__key__, self.__getstate__())
            self.__state__ = 'active'
            notification_center.post_notification('CFGSettingsObjectWasActivated', sender=self)
            notification_center.post_notification('CFGSettingsObjectWasCreated', sender=self)
            modified_data = None
        elif not modified_id and all(isinstance(self.__settings__[key], RuntimeSetting) for key in modified_settings):
            notification_center.post_notification('CFGSettingsObjectDidChange', sender=self, data=NotificationData(modified=modified_settings))
            return
        else:
            if modified_id:
                configuration.rename(oldkey, self.__key__)
            if modified_settings:
                configuration.update(self.__key__, self.__getstate__())
            modified_data = modified_settings or {}
            if modified_id:
                modified_data['__id__'] = modified_id
            notification_center.post_notification('CFGSettingsObjectDidChange', sender=self, data=NotificationData(modified=modified_data))

        try:
            configuration.save()
        except Exception as e:
            log.exception()
            notification_center.post_notification('CFGManagerSaveFailed', sender=configuration, data=NotificationData(object=self, operation='save', modified=modified_data, exception=e))
Example #6
0
    def run(self):
        self.notification_center.post_notification('SIPEngineWillStart',
                                                   sender=self)
        init_options = Engine.default_start_options.copy()
        init_options.update(self._options)
        for k in list(init_options['events'].keys()):
            if isinstance(k, str):
                init_options['events'][k.encode()] = init_options['events'][k]
                del (init_options['events'][k])

        for k in list(init_options['events'].keys()):
            init_options['events'][k] = list(
                v.encode() if isinstance(v, str) else v
                for v in init_options['events'][k])

        try:
            self._ua = PJSIPUA(self._handle_event, **init_options)
        except Exception:
            log.exception('Exception occurred while starting the Engine')
            exc_type, exc_val, exc_tb = sys.exc_info()
            exc_tb = "".join(
                traceback.format_exception(exc_type, exc_val, exc_tb))
            self.notification_center.post_notification('SIPEngineGotException',
                                                       sender=self,
                                                       data=NotificationData(
                                                           type=exc_type,
                                                           value=exc_val,
                                                           traceback=exc_tb))
            self.notification_center.post_notification('SIPEngineDidFail',
                                                       sender=self)
            return
        else:
            self.notification_center.post_notification('SIPEngineDidStart',
                                                       sender=self)
        failed = False
        while not self._thread_stopping:
            try:
                failed = self._ua.poll()
            except Exception as e:
                log.exception('Exception occurred while running the Engine')
                traceback.print_exc()
                exc_type, exc_val, exc_tb = sys.exc_info()
                self.notification_center.post_notification(
                    'SIPEngineGotException',
                    sender=self,
                    data=NotificationData(type=exc_type,
                                          value=exc_val,
                                          traceback="".join(
                                              traceback.format_exception(
                                                  exc_type, exc_val, exc_tb))))
                failed = True
            if failed:
                self.notification_center.post_notification('SIPEngineDidFail',
                                                           sender=self)
                break
        if not failed:
            self.notification_center.post_notification('SIPEngineWillEnd',
                                                       sender=self)
        self._ua.dealloc()
        del self._ua
        self.notification_center.post_notification('SIPEngineDidEnd',
                                                   sender=self)