forked from OpenELEC/service.openelec.settings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.py
executable file
·140 lines (104 loc) · 4.41 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2013 Stephan Raue ([email protected])
# Copyright (C) 2013 Lutz Fiebach ([email protected])
#
# This program is dual-licensed; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC; see the file COPYING. If not, see
# <http://www.gnu.org/licenses/>.
#
# Alternatively, you can license this library under a commercial license,
# please contact OpenELEC Licensing for more information.
#
# For more information contact:
# OpenELEC Licensing <[email protected]> http://www.openelec.tv
################################################################################
# -*- coding: utf-8 -*-
import oe
import xbmc
import xbmcgui
import time
import threading
import socket
import os
class service_thread(threading.Thread):
def __init__(self, oeMain):
try:
oeMain.dbg_log('_service_::__init__', 'enter_function', 0)
self.oe = oeMain
self.wait_evt = threading.Event()
self.socket_file = '/var/run/service.openelec.settings.sock'
self.sock = socket.socket(socket.AF_UNIX,
socket.SOCK_STREAM)
self.sock.setblocking(1)
if os.path.exists(self.socket_file):
os.remove(self.socket_file)
self.sock.bind(self.socket_file)
self.sock.listen(1)
self.stopped = False
threading.Thread.__init__(self)
self.daemon = True
self.oe.dbg_log('_service_::__init__', 'exit_function', 0)
except Exception, e:
self.oe.dbg_log('_service_::__init__', 'ERROR: (' + repr(e)
+ ')')
def stop(self):
try:
self.oe.dbg_log('_service_::stop', 'enter_function', 0)
self.stopped = True
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(self.socket_file)
sock.send('exit')
sock.close()
self.sock.close()
self.oe.dbg_log('_service_::stop', 'exit_function', 0)
except Exception, e:
self.oe.dbg_log('_service_::stop', 'ERROR: (' + repr(e)
+ ')')
def run(self):
try:
self.oe.dbg_log('_service_::run', 'enter_function', 0)
while self.stopped == False:
self.oe.dbg_log('_service_::run', 'WAITING:', 1)
(conn, addr) = self.sock.accept()
message = conn.recv(1024)
self.oe.dbg_log('_service_::run', 'MESSAGE:'
+ repr(message), 1)
conn.close()
if message == 'openConfigurationWindow':
if not hasattr(self.oe, "winOeMain"):
threading.Thread(target=self.oe.openConfigurationWindow).start()
else:
if self.oe.winOeMain.visible != True:
threading.Thread(target=self.oe.openConfigurationWindow).start()
if message == 'exit':
self.stopped = True
self.oe.dbg_log('_service_::run', 'exit_function', 0)
except Exception, e:
self.oe.dbg_log('_service_::run', 'ERROR: (' + repr(e) + ')'
)
#def onAbortRequested(self):
# self.wait_evt.set()
#def onScreensaverActivated(self):
# self.wait_evt.set()
oe.load_modules()
oe.start_service()
monitor = service_thread(oe.__oe__)
monitor.start()
while not xbmc.abortRequested:
time.sleep(1)
if hasattr(oe, "winOeMain"):
if oe.winOeMain.visible == True:
oe.winOeMain.close()
oe.stop_service()
monitor.stop()