1 This patch received help from openpli E2, thank to "Mike Looijmans <milo-software@users.sourceforge.net>"
2 diff --git a/lib/driver/Makefile.am b/lib/driver/Makefile.am
3 index a781229..28c7c55 100755
4 --- a/lib/driver/Makefile.am
5 +++ b/lib/driver/Makefile.am
6 @@ -30,6 +30,7 @@ driverinclude_HEADERS = \
14 diff --git a/lib/driver/rcinput.cpp b/lib/driver/rcinput.cpp
17 index 64757c5..84792f5
18 --- a/lib/driver/rcinput.cpp
19 +++ b/lib/driver/rcinput.cpp
20 @@ -180,8 +180,26 @@ const char *eRCDeviceInputDev::getDescription() const
22 class eInputDeviceInit
24 - ePtrList<eRCInputEventDriver> m_drivers;
25 - ePtrList<eRCDeviceInputDev> m_devices;
30 + eRCInputEventDriver *m_driver;
31 + eRCDeviceInputDev *m_device;
33 + element(const char *filename, eRCInputEventDriver *driver, eRCDeviceInputDev *device):
34 + m_filename(strdup(filename)), m_driver(driver), m_device(device)
44 + typedef std::vector<element*> itemlist;
49 @@ -193,9 +211,8 @@ public:
50 sprintf(filename, "/dev/input/event%d", i);
51 if (stat(filename, &s))
53 - eRCInputEventDriver *p;
54 - m_drivers.push_back(p = new eRCInputEventDriver(filename));
55 - m_devices.push_back(new eRCDeviceInputDev(p));
60 eDebug("Found %d input devices!", i);
61 @@ -203,14 +220,60 @@ public:
65 - while (m_drivers.size())
66 + for (itemlist::iterator it = m_items.begin(); it != m_items.end(); ++it)
68 - delete m_devices.back();
69 - m_devices.pop_back();
70 - delete m_drivers.back();
71 - m_drivers.pop_back();
76 + void add(const char* filename)
78 + bool no_exist = false;
79 + for (itemlist::iterator it = m_items.begin(); it != m_items.end(); ++it)
81 + if (strcmp((*it)->m_filename, filename) == 0)
83 + eDebug("[eInputDeviceInit] %s is already added.", filename);
91 + eDebug("[eInputDeviceInit] adding device %s", filename);
92 + eRCInputEventDriver *driver = new eRCInputEventDriver(filename);
93 + eRCDeviceInputDev *device = new eRCDeviceInputDev(driver);
94 + m_items.push_back(new element(filename, driver, device));
98 + void remove(const char* filename)
100 + for (itemlist::iterator it = m_items.begin(); it != m_items.end(); ++it)
102 + if (strcmp((*it)->m_filename, filename) == 0)
104 + eDebug("[eInputDeviceInit] remove device %s", filename);
111 + eDebug("[eInputDeviceInit] Remove '%s', not found", filename);
115 eAutoInitP0<eInputDeviceInit> init_rcinputdev(eAutoInitNumbers::rc+1, "input device driver");
117 +void addInputDevice(const char* filename)
119 + init_rcinputdev->add(filename);
122 +void removeInputDevice(const char* filename)
124 + init_rcinputdev->remove(filename);
127 diff --git a/lib/driver/rcinput_swig.h b/lib/driver/rcinput_swig.h
129 index 0000000..f640f58
131 +++ b/lib/driver/rcinput_swig.h
133 +void addInputDevice(const char* filename);
134 +void removeInputDevice(const char* filename);
136 diff --git a/lib/python/Components/InputHotplug.py b/lib/python/Components/InputHotplug.py
138 index 0000000..267be03
140 +++ b/lib/python/Components/InputHotplug.py
146 +class NetlinkReader():
147 + def __init__(self):
148 + from twisted.internet import reactor
149 + self.nls = Netlink.NetlinkSocket()
150 + reactor.addReader(self)
153 + return self.nls.fileno()
155 + for event in self.nls.parse():
157 + subsystem = event['SUBSYSTEM']
158 + if subsystem == 'input':
159 + devname = event['DEVNAME']
160 + action = event['ACTION']
161 + if action == 'add':
162 + print "New input device detected:", devname
163 + enigma.addInputDevice(os.path.join('/dev', devname));
164 + elif action == 'remove':
165 + print "Removed input device:", devname
166 + enigma.removeInputDevice(os.path.join('/dev', devname));
167 + elif subsystem == 'net':
168 + from Network import iNetwork
169 + iNetwork.hotplug(event)
171 + # Ignore "not found"
173 + def connectionLost(self, failure):
175 + print "connectionLost?", failure
177 + def logPrefix(self):
178 + return 'NetlinkReader'
180 +reader = NetlinkReader()
181 diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am
182 index b5ef068..748caf5 100755
183 --- a/lib/python/Components/Makefile.am
184 +++ b/lib/python/Components/Makefile.am
185 @@ -19,4 +19,4 @@ install_PYTHON = \
186 Element.py Playlist.py ParentalControl.py ParentalControlList.py \
187 Ipkg.py SelectionList.py Scanner.py SystemInfo.py DreamInfoHandler.py \
188 Task.py language_cache.py Console.py ResourceManager.py TuneTest.py \
189 - Keyboard.py Sensors.py FanControl.py
190 + Keyboard.py Sensors.py FanControl.py InputHotplug.py Netlink.py
191 diff --git a/lib/python/Components/Netlink.py b/lib/python/Components/Netlink.py
193 index 0000000..026f420
195 +++ b/lib/python/Components/Netlink.py
197 +# Listen to hotplug events. Can be used to listen for hotplug events and
198 +# similar things, like network connections being (un)plugged.
202 +class NetlinkSocket(socket.socket):
203 + def __init__(self):
204 + NETLINK_KOBJECT_UEVENT = 15 # hasn't landed in socket yet, see linux/netlink.h
205 + socket.socket.__init__(self, socket.AF_NETLINK, socket.SOCK_DGRAM, NETLINK_KOBJECT_UEVENT)
206 + self.bind((os.getpid(), -1))
209 + data = self.recv(512)
211 + for item in data.split('\x00'):
218 + k,v = item.split('=', 1)
223 +# Quick unit test (you can run this on any Linux machine)
224 +if __name__ == '__main__':
225 + nls = NetlinkSocket()
226 + print "socket no:", nls.fileno()
228 + for item in nls.parse():
230 diff --git a/lib/python/Components/Network.py b/lib/python/Components/Network.py
231 index c39d1ba..2390bac 100755
232 --- a/lib/python/Components/Network.py
233 +++ b/lib/python/Components/Network.py
234 @@ -693,6 +693,21 @@ class Network:
235 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKCONFIG_READ):
236 p(reason=self.config_ready)
238 + def hotplug(self, event):
239 + interface = event['INTERFACE']
240 + if self.isBlacklisted(interface):
242 + action = event['ACTION']
243 + if action == "add":
244 + print "[Network] Add new interface:", interface
245 + self.getAddrInet(interface, None)
246 + elif action == "remove":
247 + print "[Network] Removed interface:", interface
249 + del self.ifaces[interface]
253 def getInterfacesNameserverList(self, iface):
255 nameservers = self.getAdapterAttribute(iface, "dns-nameservers")
256 diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i
257 index e9a8161..dc49082 100755
258 --- a/lib/python/enigma_python.i
259 +++ b/lib/python/enigma_python.i
260 @@ -44,6 +44,7 @@ is usually caused by not marking PSignals as immutable.
261 #include <lib/base/nconfig.h>
262 #include <lib/base/message.h>
263 #include <lib/driver/rc.h>
264 +#include <lib/driver/rcinput_swig.h>
265 #include <lib/service/event.h>
266 #include <lib/service/iservice.h>
267 #include <lib/service/service.h>
268 @@ -169,6 +170,7 @@ typedef long time_t;
269 %include <lib/base/etpm.h>
270 %include <lib/base/nconfig.h>
271 %include <lib/driver/rc.h>
272 +%include <lib/driver/rcinput_swig.h>
273 %include <lib/gdi/fb.h>
274 %include <lib/gdi/font.h>
275 %include <lib/gdi/gpixmap.h>
276 diff --git a/mytest.py b/mytest.py
277 index 99695e0..1daf20b 100755
280 @@ -544,6 +544,7 @@ skin.loadSkinData(getDesktop(0))
281 profile("InputDevice")
282 import Components.InputDevice
283 Components.InputDevice.InitInputDevices()
284 +import Components.InputHotplug
287 import Components.AVSwitch