Kodi Community Forum
methods to reload service ? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: methods to reload service ? (/showthread.php?tid=232331)



methods to reload service ? - reaven - 2015-07-16

just wondering what methods exist to reload a service based
Code:
onSettingsChanged()
?
Thanks !


RE: methods to reload service ? - el_Paraguayo - 2015-07-16

I've probably been doing it all wrong (so I'll be interested in any other answers to this thread!) but my approach was that I didn't want to restart the service, instead, I wanted the new settings to have effect from that point.

All I ended up doing was just reloading the settings in the service loop and updating variables as necessary.

It's not big, it's not clever, but it works for me.


RE: methods to reload service ? - ronie - 2015-07-16

here's what i use to load new settings:

PHP Code:
class Main:
    
def __init__self ):
        
self._service_setup()
        while (
not self.Monitor.abortRequested()):
            
# rest of your code here
            
xbmc.sleep(1000)

    
def _service_setupself ):
        
self.Monitor MyMonitor(action self._get_settings)
        
self._get_settings

    def _get_settings
self ):
        
self.user __addon__.getSetting('username')
        
self.pass __addon__.getSetting('password')

class 
MyMonitor(xbmc.Monitor):
    
def __init__self, *args, **kwargs ):
        
xbmc.Monitor.__init__self )
        
self.action kwargs['action']

    
def onSettingsChangedself ):
        
self.action() 



RE: methods to reload service ? - el_Paraguayo - 2015-07-17

Maybe it's time to change my code... That's far more professional than my "solution"!

Thanks for sharing, ronie.


RE: methods to reload service ? - reaven - 2015-07-19

thank ronie, I would try that !

I would think there was a kodi method to do that like
Ex.(made up)
Code:
xbmc.Addon().reloadAddon()
or something instead of reloading variables and settings individually.


RE: methods to reload service ? - maikito26 - 2015-09-10

Need some help. I can't seem to get Kodi to recognize settings being changed. There doesn't seem to be an event created when they change. I've called the onSettingsChanged() routine directly and it works so there shouldn't be an error its getting caught on. The main program just chugs along and there aren't any logs written from the restart routine.

Any ideas what I might be doing wrong? Here's the code below.

Code:
class  Main:
    def __init__(self):  
        self._reset = False            #Reset used to kill threaded loops in main program
        self.Monitor = MyMonitor(action = self.restart)
        self.start()

    def restart(self):
        common.log_verbose("A setting change has been detected!")
        self._reset = False    
        common.log_normal("Applying changed settings in 10 seconds")
        self.Monitor.waitForAbort(10)
        self._reset = True
        self.start()
  
    def start(self):
    
        #Main Code here

        
class MyMonitor(xbmc.Monitor):
    def __init__(self, *args, **kwargs):
        xbmc.Monitor.__init__(self)
        self.action = kwargs['action']
        
    def onSettingsChanged(self):
        self.action()
  
  
      
if __name__ == '__main__':
    Main()



RE: methods to reload service ? - maikito26 - 2015-09-12

I'll post this here for other people. I solve my problem. In the main code I was threading. In each of those threads they looped. But the main thread ends so I had to add a loop that doesn't do anything at the end of the code to keep the monitor alive to act on settings changes. I figured it out on a fluke when I accidentally killed the thread initializing.

Code:
class  Main:
     def __init__(self):  
         self._reset = False            #Reset used to kill threaded loops in main program
         self.Monitor = MyMonitor(action = self.restart)
         self.start()

     def restart(self):
         common.log_verbose("A setting change has been detected!")
         self._reset = False    
         common.log_normal("Applying changed settings in 10 seconds")
         self.Monitor.waitForAbort(10)
         self._reset = True
         self.start()
    
     def start(self):
    
         #Main Code here - Started threads that looped.  This didn't work until the loop was added below - even though I had other loops processing.  

         while not self.Monitor.abortRequested():
             xbmc.sleep(1000)

        
class MyMonitor(xbmc.Monitor):
     def __init__(self, *args, **kwargs):
         xbmc.Monitor.__init__(self)
         self.action = kwargs['action']
        
     def onSettingsChanged(self):
         self.action()
    
    
        
if __name__ == '__main__':
     Main()