This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
/
system-service.py
executable file
·218 lines (200 loc) · 7.34 KB
/
system-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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/python2
# coding=UTF-8
#
# Samsung-Tools
#
# Part of the 'Linux On My Samsung' project - <http://loms.voria.org>
#
# Copyleft (C) 2010 by
# Fortunato Ventre - <vorione@gmail.com> - <http://www.voria.org>
#
# 'Samsung-Tools' is free software; 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 3 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.
# <http://www.gnu.org/licenses/gpl.txt>
import os
import gobject
import subprocess
import dbus
import dbus.service
import dbus.mainloop.glib
from backends.globals import *
from backends.system.options import Options
from backends.system.backlight import Backlight
from backends.system.bluetooth import Bluetooth
from backends.system.cpu import Cpu
from backends.system.fan import Fan
from backends.system.webcam import Webcam
from backends.system.wireless import Wireless
from backends.system.powermanagement import SysCtl
from backends.system.powermanagement import PowerManagement
mainloop = None
bluetooth = None
cpu = None
fan = None
webcam = None
wireless = None
class General(dbus.service.Object):
def __init__(self, conn=None, object_path=None, bus_name=None):
dbus.service.Object.__init__(self, conn, object_path, bus_name)
# Make sure the directory for last devices status exists
if not os.path.exists(LAST_DEVICES_STATUS_DIRECTORY):
os.mkdir(LAST_DEVICES_STATUS_DIRECTORY)
# Select the interface we are going to use
if self.__check_for_esdm_module():
self.__set_control_interface("esdm")
elif self.__check_for_sl_module():
self.__set_control_interface("sl")
else:
systemlog.write(
"WARNING: 'General.__init__()' - Cannot find any usable interface! " +
"Many of the functionalities will not work.")
self.__set_control_interface("none")
def __set_control_interface(self, interface):
try:
file = open(CONTROL_INTERFACE, 'w')
file.write(interface)
file.close()
except:
systemlog.write(
"ERROR: Cannot write to file '" + CONTROL_INTERFACE + "'!")
self.Exit()
def __check_for_esdm_module(self):
""" Check for the 'easy-slow-down-manager' interface. """
""" Return 'True' if it can be used, 'False' otherwise. """
if os.path.exists(ESDM_PATH_PERFORMANCE):
return True # kernel module already loaded and ready to use
try:
command = COMMAND_MODPROBE + " " + ESDM_MODULE
process = subprocess.Popen(
command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
process.communicate()
except:
systemlog.write(
"WARNING: 'General.__check_for_esdm_module()' - COMMAND: '" +
command +
"' - Exception thrown.")
return False
if process.returncode != 0:
return False
else:
return True
def __check_for_sl_module(self):
""" Check for the 'samsung-laptop' interface. """
""" Return 'True' if it can be used, 'False' otherwise. """
if os.path.exists(SL_PATH_PERFORMANCE):
return True # kernel module already loaded and ready to use
try:
command = COMMAND_MODPROBE + " " + SL_MODULE
process = subprocess.Popen(
command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
process.communicate()
except:
systemlog.write(
"WARNING: 'General.__check_for_sl_module()' - COMMAND: '" +
command +
"' - Exception thrown.")
return False
if process.returncode != 0:
return False
else:
return True
@dbus.service.method(
SYSTEM_INTERFACE_NAME,
in_signature=None,
out_signature=None,
sender_keyword='sender',
connection_keyword='conn')
def RestoreDevicesLastStatus(self, sender=None, conn=None):
""" Restore last status for everything. """
""" Return nothing. """
bluetooth.RestoreLastStatus()
webcam.RestoreLastStatus()
wireless.RestoreLastStatus()
fan.RestoreLastStatus()
# Restore also PHC values, just in case they have been reset
status = systemconfig.getPHCVids()
if status != "":
cpu.SetCurrentVids(status)
@dbus.service.method(
SYSTEM_INTERFACE_NAME,
in_signature=None,
out_signature=None,
sender_keyword='sender',
connection_keyword='conn')
def SetInitialDevicesStatus(self, sender=None, conn=None):
""" Set initial status for everything. """
""" Return nothing. """
# Bluetooth
status = systemconfig.getBluetoothInitialStatus()
if status == "on":
bluetooth.Enable()
elif status == "off":
bluetooth.Disable()
else: # status == "last":
bluetooth.RestoreLastStatus()
# Webcam
status = systemconfig.getWebcamInitialStatus()
if status == "on":
webcam.Enable()
elif status == "off":
webcam.Disable()
else: # status == "last"
webcam.RestoreLastStatus()
# Wireless
status = systemconfig.getWirelessInitialStatus()
if status == "on":
wireless.Enable()
elif status == "off":
wireless.Disable()
else: # status == "last"
wireless.RestoreLastStatus()
# CPU fan
status = systemconfig.getCpufanInitialStatus()
if status == "normal":
fan.SetNormal()
elif status == "silent":
fan.SetSilent()
elif status == "overclock":
fan.SetOverclock()
else: # status == "last"
fan.RestoreLastStatus()
# PHC
status = systemconfig.getPHCVids()
if status != "":
cpu.SetCurrentVids(status)
@dbus.service.method(
SYSTEM_INTERFACE_NAME,
in_signature=None,
out_signature=None,
sender_keyword='sender',
connection_keyword='conn')
def Exit(self, sender=None, conn=None):
mainloop.quit()
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
name = dbus.service.BusName(SYSTEM_INTERFACE_NAME, bus)
General(bus, SYSTEM_OBJECT_PATH_GENERAL)
Options(bus, SYSTEM_OBJECT_PATH_OPTIONS)
Backlight(bus, SYSTEM_OBJECT_PATH_BACKLIGHT)
SysCtl(bus, SYSTEM_OBJECT_PATH_SYSCTL)
PowerManagement(bus, SYSTEM_OBJECT_PATH_POWERMANAGEMENT)
# We need these objects for restoring last statuses
bluetooth = Bluetooth(bus, SYSTEM_OBJECT_PATH_BLUETOOTH)
cpu = Cpu(bus, SYSTEM_OBJECT_PATH_CPU)
fan = Fan(bus, SYSTEM_OBJECT_PATH_FAN)
webcam = Webcam(bus, SYSTEM_OBJECT_PATH_WEBCAM)
wireless = Wireless(bus, SYSTEM_OBJECT_PATH_WIRELESS)
mainloop = gobject.MainLoop()
mainloop.run()