Exemple #1
0
def serviceMethod(name, **params):
    actionId = __registered_services__[name]
    data = {'data': AddonUtils.encodeData(params)}
    service_response_obj = None
    try:
        containerObj = Container(addon_id=__addon_id__)

        iconimage = AddonUtils.getCompleteFilePath(
            baseDirPath=containerObj.getAddonContext().addonPath,
            filename='icon.png')
        XBMCInterfaceUtils.displayNotification(
            __service_name__ + ' Service',
            'Processing received request...',
            iconimage=iconimage)

        containerObj.reloadTurtleRequest(data)
        containerObj.performAction(actionId)
        service_response_obj = containerObj.getTurtleResponse(
        ).get_service_response_obj()
    except Exception, e:
        print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e)
        ExceptionHandler.handle(e)
        service_response_obj = {
            "status": "exception",
            "message": "an unexpected error occurred, please check your input"
        }
        XBMCInterfaceUtils.displayNotification(
            __service_name__ + ' Service',
            'Error while processing your request',
            time='5000')
Exemple #2
0
def start(addon_id, service_name, context_root, default_port,
          allowed_port_range):
    try:
        global __addon_id__
        global __registered_services__
        global __context_root__
        global __port__
        global __port_range__
        global __service_name__
        __addon_id__ = addon_id
        __context_root__ = context_root
        __port__ = default_port
        __port_range__ = allowed_port_range
        __service_name__ = service_name
        containerObj = Container(addon_id=addon_id)
        iconimage = AddonUtils.getCompleteFilePath(
            baseDirPath=containerObj.getAddonContext().addonPath,
            filename='icon.png')
        serviceport = int(
            containerObj.getAddonContext().addon.getSetting('serviceport'))

        XBMCInterfaceUtils.setSuppressDialogMsg(True)

        if serviceport < __port_range__[0] or serviceport > __port_range__[1]:
            containerObj.getAddonContext().addon.setSetting(
                'serviceport', str(__port__))
            serviceport = __port__
            XBMCInterfaceUtils.displayNotification(
                __service_name__ + ' Service: Port updated',
                'Service port set to default value 8181',
                iconimage=iconimage)

        server = JSONRPCServer(context_root=__context_root__,
                               server_port=serviceport)
        server.registerService('serviceName', serviceMethod)
        defined_services = containerObj.getAddonContext().getTurtleServices()
        if len(defined_services) == 0:
            print __service_name__ + ' Service :: There are no services defined for registration, end this service program now.'
            return
        for service in defined_services:
            server.registerService(service.get_service_name(), serviceMethod)
            __registered_services__[
                service.get_service_name()] = service.get_action_id()
            print __service_name__ + ' Service :: service registered = %s @ %s' % (
                service.get_service_name(), __context_root__)
        server.start()
        XBMCInterfaceUtils.displayNotification(
            __service_name__ + ' Service has started',
            'Use safari extension to play video remotely',
            iconimage=iconimage)

        while not xbmc.abortRequested:
            time.sleep(5)
        print __service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.'
    except Exception, e:
        print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e)
        ExceptionHandler.handle(e)
Exemple #3
0
def start(addon_id, service_name, context_root, default_port, allowed_port_range):
    server = None
    try:
        sys.argv = None  # To handle the situations where some library expects system arguments. Main change made for t0mm0 urlresolver library.
        
        global __addon_id__
        global __registered_services__
        global __context_root__
        global __port__
        global __port_range__
        global __service_name__
        __addon_id__ = addon_id
        __context_root__ = context_root
        __port__ = default_port
        __port_range__ = allowed_port_range
        __service_name__ = service_name
        containerObj = Container(addon_id=addon_id)
        iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png')
        serviceport = int(containerObj.getAddonContext().addon.getSetting('serviceport'))
        
        XBMCInterfaceUtils.setSuppressDialogMsg(True)
        
        if serviceport < __port_range__[0] or serviceport > __port_range__[1] :
            containerObj.getAddonContext().addon.setSetting('serviceport', str(__port__))
            serviceport = __port__
            XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service: Port updated', 'Service port set to default value 8181', iconimage=iconimage)

        server = JSONRPCServer(context_root=__context_root__, server_port=serviceport)
        server.registerService('serviceName', serviceMethod)
        defined_services = containerObj.getAddonContext().getTurtleServices()
        if len(defined_services) == 0:
            Logger.logError(__service_name__ + ' Service :: There are no services defined for registration, end this service program now.')
            return
        for service in defined_services:
            server.registerService(service.get_service_name(), serviceMethod)
            __registered_services__[service.get_service_name()] = service.get_action_id()
            Logger.logInfo(__service_name__ + ' Service :: service registered = %s @ %s' % (service.get_service_name(), __context_root__))
        server.start()
#         XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service has started', 'Use web browser PlayIt extension to play video.', iconimage=iconimage)
        
        while not xbmc.abortRequested:
            time.sleep(1)
        Logger.logInfo(__service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.')
    except Exception, e:
        Logger.logFatal(__service_name__ + ' Service :: ERROR OCCURRED: ' + str(e))
        ExceptionHandler.handle(e)
def serviceMethod(name, **params):
    actionId = __registered_services__[name]
    data = {'data':AddonUtils.encodeData(params)}
    service_response_obj = None
    try:
        containerObj = Container(addon_id=__addon_id__)
        
        iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png')
        XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service', 'Processing received request...', iconimage=iconimage)
    
        containerObj.reloadTurtleRequest(data)
        containerObj.performAction(actionId)
        service_response_obj = containerObj.getTurtleResponse().get_service_response_obj()
    except Exception, e:
        print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e)
        ExceptionHandler.handle(e)
        service_response_obj = {"status":"exception", "message":"an unexpected error occurred, please check your input"}
        XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service', 'Error while processing your request', time='5000')
def start(addon_id, service_name, context_root, default_port, allowed_port_range):
    try:
        global __addon_id__
        global __registered_services__
        global __context_root__
        global __port__
        global __port_range__
        global __service_name__
        __addon_id__ = addon_id
        __context_root__ = context_root
        __port__ = default_port
        __port_range__ = allowed_port_range
        __service_name__ = service_name
        containerObj = Container(addon_id=addon_id)
        iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png')
        serviceport = int(containerObj.getAddonContext().addon.getSetting('serviceport'))
        
        XBMCInterfaceUtils.setSuppressDialogMsg(True)
        
        if serviceport < __port_range__[0] or serviceport > __port_range__[1] :
            containerObj.getAddonContext().addon.setSetting('serviceport', str(__port__))
            serviceport = __port__
            XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service: Port updated', 'Service port set to default value 8181', iconimage=iconimage)

        server = JSONRPCServer(context_root=__context_root__, server_port=serviceport)
        server.registerService('serviceName', serviceMethod)
        defined_services = containerObj.getAddonContext().getTurtleServices()
        if len(defined_services) == 0:
            print __service_name__ + ' Service :: There are no services defined for registration, end this service program now.'
            return
        for service in defined_services:
            server.registerService(service.get_service_name(), serviceMethod)
            __registered_services__[service.get_service_name()] = service.get_action_id()
            print __service_name__ + ' Service :: service registered = %s @ %s' % (service.get_service_name(), __context_root__)
        server.start()
        XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service has started', 'Use safari extension to play video remotely', iconimage=iconimage)
        
        while not xbmc.abortRequested:
            time.sleep(5)
        print __service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.'
    except Exception, e:
        print __service_name__ + ' Service :: ERROR OCCURRED: ' + str(e)
        ExceptionHandler.handle(e)