Example #1
0
    def start(self, *args, **kwargs):
        log.debug("service start")
        for state_variable in self._state_variables.itervalues():
            if state_variable.send_events == True:
                if self.eventSub_controller == None:
                    self.eventSub_controller = EventController(
                        self, self._event_reload_time,
                        self._force_event_reload)
#                if not self.multicast_event_controller and state_variable.multicast:
                if self.multicast_event_controller == None:
                    self.multicast_event_controller = MulticastEventController(
                        self.parent_udn, self, self._event_reload_time,
                        self._force_event_reload)
                    self.multicast_event_controller.start()
Example #2
0
 def start(self, *args, **kwargs):
     for state_variable in self._state_variables.itervalues():
         if state_variable.send_events:
             if not self.eventSub_controller:
                 self.eventSub_controller = EventController(self, self._event_reload_time, self._force_event_reload)
             if not self.multicast_event_controller and state_variable.multicast:
                 self.multicast_event_controller = MulticastEventController(
                     self.parent_udn, self, self._event_reload_time, self._force_event_reload
                 )
                 self.multicast_event_controller.start()
Example #3
0
    def start(self, *args, **kwargs):
        log.debug("service start")
        for state_variable in self._state_variables.itervalues():
            if  state_variable.send_events == True:
                if self.eventSub_controller == None:
                    self.eventSub_controller = EventController(self, self._event_reload_time,
                                                               self._force_event_reload)
#                if not self.multicast_event_controller and state_variable.multicast:
                if self.multicast_event_controller == None:
                    self.multicast_event_controller = MulticastEventController(self.parent_udn,
                                                                    self, self._event_reload_time,
                                                                    self._force_event_reload)
                    self.multicast_event_controller.start()
Example #4
0
class Service(BaseService):

    def __init__(self, id, serv_type, url_base='',
                 scpd_xml_filepath='', presentation_controller=None):
        BaseService.__init__(self, id, serv_type, url_base)

        self.control_controller = ServiceController(self, self.service_type)
        self.eventSub_controller = None
        self.multicast_event_controller = None
        self.presentation_controller = presentation_controller
        self.parent_udn = None

        try:
            self._event_reload_time = int(config.get_parameter('brisa', 'event_reload_time'))
            if self._event_reload_time < 0:
                self._event_reload_time = 0
        except:
            self._event_reload_time = 30

        try:
            self._force_event_reload = config.get_parameter('brisa', 'force_event_reload')
            if self._force_event_reload.lower() == 'true' or self._force_event_reload == '1':
                self._force_event_reload = True
            else:
                self._force_event_reload = False
        except:
            self._force_event_reload = False 


        if not scpd_xml_filepath:
            self._generate_xml()
            self._create_xml = True
        else:
            self._xml_filepath = scpd_xml_filepath
            fd = open(self._xml_filepath, 'r')
            if not ServiceBuilder(self, fd).build():
                raise InvalidService('Error building the service %s' % id)
            fd.close()
            self._create_xml = False

    def publish(self, webserver):
        log.info('Publishing service %s' % self.id)

        if not len(self.get_variables()):
            raise InvalidService('The service must have one '\
                                        'or more state variables')

        res = webserver.CustomResource(self.id)
        if self._create_xml:
            ServiceXMLBuilder(self).generate_to_file(self._xml_filepath)
        f = webserver.StaticFile('scpd.xml', self._xml_filepath)
        res.add_static_file(f)

        for k in ['control', 'eventSub', 'presentation']:
            controller = getattr(self, '%s_controller' % k)
            if controller:
                res.add_resource(controller)

        webserver.add_resource(res)

    def add_state_variable(self, state_variable):
        self._state_variables[state_variable.name] = state_variable

    def set_state_variable(self, name, value):
        state_variable = self._state_variables[name]
        state_variable.update(value)

    def _set_event_reload_time(self, time):
        self._event_reload_time = time

    def _set_force_event_reload(self, force):
        self._force_event_reload = force

    def add_action(self, action):
        action.service = self
        self._actions[action.name] = action

    def start(self, *args, **kwargs):
        for state_variable in self._state_variables.itervalues():
            if  state_variable.send_events:
                if not self.eventSub_controller:
                    self.eventSub_controller = EventController(self, self._event_reload_time,
                                                               self._force_event_reload)
                if not self.multicast_event_controller and state_variable.multicast:
                    self.multicast_event_controller = MulticastEventController(self.parent_udn,
                                                                    self, self._event_reload_time,
                                                                    self._force_event_reload)
                    self.multicast_event_controller.start()

    def stop(self):
        if self.multicast_event_controller:
            self.multicast_event_controller.stop()

    def _generate_xml(self):
        self.xml_filename = '%s-scpd.xml' % self.id
        self.xml_filename = self.xml_filename.replace(' ', '')
        self._xml_filepath = path.join(config.manager.brisa_home, 'tmp_xml')
        if not path.exists(self._xml_filepath):
            mkdir(self._xml_filepath)
        self._xml_filepath = path.join(self._xml_filepath, self.xml_filename)
Example #5
0
class Service(BaseService):
    def __init__(self,
                 id,
                 serv_type,
                 url_base='',
                 scpd_xml_filepath='',
                 presentation_controller=None):
        BaseService.__init__(self, id, serv_type, url_base)

        self.control_controller = ServiceController(self, self.service_type)
        self.eventSub_controller = None
        self.multicast_event_controller = None
        self.presentation_controller = presentation_controller
        self.parent_udn = None

        try:
            self._event_reload_time = int(
                config.get_parameter('brisa', 'event_reload_time'))
            if self._event_reload_time < 0:
                self._event_reload_time = 0
        except:
            self._event_reload_time = 30

        try:
            self._force_event_reload = config.get_parameter(
                'brisa', 'force_event_reload')
            if self._force_event_reload.lower(
            ) == 'true' or self._force_event_reload == '1':
                self._force_event_reload = True
            else:
                self._force_event_reload = False
        except:
            self._force_event_reload = False

        if not scpd_xml_filepath:
            self._generate_xml()
            self._create_xml = True
        else:
            self._xml_filepath = scpd_xml_filepath
            fd = open(self._xml_filepath, 'r')
            if not ServiceBuilder(self, fd).build():
                raise InvalidService('Error building the service %s' % id)
            fd.close()
            self._create_xml = False

    def publish(self, webserver):
        log.info('Publishing service %s' % self.id)

        if not len(self.get_variables()):
            raise InvalidService('The service must have one '\
                                        'or more state variables')

        res = webserver.CustomResource(self.id)
        if self._create_xml:
            ServiceXMLBuilder(self).generate_to_file(self._xml_filepath)
        f = webserver.StaticFile('scpd.xml', self._xml_filepath)
        res.add_static_file(f)

        for k in ['control', 'eventSub', 'presentation']:
            log.info('Publishing service, controller %s' % k)
            controller = getattr(self, '%s_controller' % k)
            if controller:
                log.info('Publishing service, controller, add_resource %s' %
                         controller)
                res.add_resource(controller)

        webserver.add_resource(res)

    def add_state_variable(self, state_variable):
        #        print "AAAAAAAAAAAAAAAAAAAAA"
        #        print "service.add_state_variable: " + str(state_variable)
        #        print "service.eventSub_controller: " + str(self.eventSub_controller)
        #        print "AAAAAAAAAAAAAAAAAAAAA"
        self._state_variables[state_variable.name] = state_variable

    def set_state_variable(self, name, value):
        state_variable = self._state_variables[name]
        state_variable.update(value)

    def _set_event_reload_time(self, time):
        self._event_reload_time = time

    def _set_force_event_reload(self, force):
        self._force_event_reload = force

    def add_action(self, action):
        action.service = self
        self._actions[action.name] = action

    def start(self, *args, **kwargs):
        log.debug("service start")
        for state_variable in self._state_variables.itervalues():
            if state_variable.send_events == True:
                if self.eventSub_controller == None:
                    self.eventSub_controller = EventController(
                        self, self._event_reload_time,
                        self._force_event_reload)
#                if not self.multicast_event_controller and state_variable.multicast:
                if self.multicast_event_controller == None:
                    self.multicast_event_controller = MulticastEventController(
                        self.parent_udn, self, self._event_reload_time,
                        self._force_event_reload)
                    self.multicast_event_controller.start()

    def stop(self):
        if self.multicast_event_controller:
            self.multicast_event_controller.stop()

    def _generate_xml(self):
        self.xml_filename = '%s-scpd.xml' % self.id
        self.xml_filename = self.xml_filename.replace(' ', '')
        self._xml_filepath = path.join(config.manager.brisa_home, 'tmp_xml')
        if not path.exists(self._xml_filepath):
            mkdir(self._xml_filepath)
        self._xml_filepath = path.join(self._xml_filepath, self.xml_filename)