support for a final post-destroy value
[enigma2.git] / lib / python / Components / Network.py
index 7cc61d847516da7cfef0b0995ddbde81c3f4ef1e..5f7095c4078eeaec9541ff13c47d4c143ccdfb00 100755 (executable)
@@ -3,6 +3,8 @@ from re import compile as re_compile, search as re_search
 from socket import *
 from enigma import eConsoleAppContainer
 from Components.Console import Console
+from Components.PluginComponent import plugins
+from Plugins.Plugin import PluginDescriptor
 
 class Network:
        def __init__(self):
@@ -22,6 +24,7 @@ class Network:
                self.activateConsole = Console()
                self.resetNetworkConsole = Console()
                self.DnsConsole = Console()
+               self.config_ready = None
                self.getInterfaces()
 
        def getInterfaces(self, callback = None):
@@ -63,6 +66,8 @@ class Network:
 
        def getDataForInterface(self, iface,callback):
                #get ip out of ip addr, as avahi sometimes overrides it in ifconfig.
+               if not self.Console:
+                       self.Console = Console()
                cmd = "ip -o addr"
                self.Console.ePopen(cmd, self.IPaddrFinished, [iface,callback])
 
@@ -201,7 +206,7 @@ class Network:
                                        ifaces[currif]["gateway"] = map(int, split[1].split('.'))
                                        if self.ifaces[currif].has_key("gateway"):
                                                if self.ifaces[currif]["gateway"] != ifaces[currif]["gateway"] and ifaces[currif]["dhcp"] == False:
-                                                       self.ifaces[currif]["gateway"] = map(int, split[1].split('.'))                                  
+                                                       self.ifaces[currif]["gateway"] = map(int, split[1].split('.'))
                                if (split[0] == "pre-up"):
                                        if self.ifaces[currif].has_key("preup"):
                                                self.ifaces[currif]["preup"] = i
@@ -212,15 +217,18 @@ class Network:
                for ifacename, iface in ifaces.items():
                        if self.ifaces.has_key(ifacename):
                                self.ifaces[ifacename]["dhcp"] = iface["dhcp"]
-               if len(self.Console.appContainers) == 0:
-                       # save configured interfacelist
-                       self.configuredNetworkAdapters = self.configuredInterfaces
-                       # load ns only once     
-                       self.loadNameserverConfig()
-                       print "read configured interfac:", ifaces
-                       print "self.ifaces after loading:", self.ifaces
-                       if callback is not None:
-                               callback(True)
+               if self.Console:
+                       if len(self.Console.appContainers) == 0:
+                               # save configured interfacelist
+                               self.configuredNetworkAdapters = self.configuredInterfaces
+                               # load ns only once     
+                               self.loadNameserverConfig()
+                               print "read configured interfac:", ifaces
+                               print "self.ifaces after loading:", self.ifaces
+                               self.config_ready = True
+                               self.msgPlugins()
+                               if callback is not None:
+                                       callback(True)
 
        def loadNameserverConfig(self):
                ipRegexp = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
@@ -415,6 +423,8 @@ class Network:
                
        def restartNetwork(self,callback = None):
                self.restartConsole = Console()
+               self.config_ready = False
+               self.msgPlugins()
                self.commands = []
                self.commands.append("/etc/init.d/avahi-daemon stop")
                for iface in self.ifaces.keys():
@@ -445,24 +455,34 @@ class Network:
                        
        def stopLinkStateConsole(self):
                if self.LinkConsole is not None:
-                       self.LinkConsole = None
-
+                       if len(self.LinkConsole.appContainers):
+                               for name in self.LinkConsole.appContainers.keys():
+                                       self.LinkConsole.kill(name)
+                                       
        def stopDNSConsole(self):
                if self.DnsConsole is not None:
-                       self.DnsConsole = None
-
+                       if len(self.DnsConsole.appContainers):
+                               for name in self.DnsConsole.appContainers.keys():
+                                       self.DnsConsole.kill(name)
+                                       
        def stopRestartConsole(self):
                if self.restartConsole is not None:
-                       self.restartConsole = None
-                       
+                       if len(self.restartConsole.appContainers):
+                               for name in self.restartConsole.appContainers.keys():
+                                       self.restartConsole.kill(name)
+                                       
        def stopGetInterfacesConsole(self):
                if self.Console is not None:
-                       self.Console = None
-
+                       if len(self.Console.appContainers):
+                               for name in self.Console.appContainers.keys():
+                                       self.Console.kill(name)
+                                       
        def stopDeactivateInterfaceConsole(self):
-               if self.deactivateInterfaceConsole:
-                       self.deactivateInterfaceConsole = None
-                       
+               if self.deactivateInterfaceConsole is not None:
+                       if len(self.deactivateInterfaceConsole.appContainers):
+                               for name in self.deactivateInterfaceConsole.appContainers.keys():
+                                       self.deactivateInterfaceConsole.kill(name)
+                                       
        def checkforInterface(self,iface):
                if self.getAdapterAttribute(iface, 'up') is True:
                        return True
@@ -544,6 +564,11 @@ class Network:
                        netmask = str(inet_ntoa(pack('>L', nm)))
                        return netmask
        
+       def msgPlugins(self):
+               if self.config_ready is not None:
+                       for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKCONFIG_READ):
+                               p(reason=self.config_ready)
+       
 iNetwork = Network()
 
 def InitNetwork():