aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/NimManager.py
blob: d826dbe4f71daece764ff534e85206937fb03391 (plain)
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
from config import config       #global config instance

from config import configElement
from config import ConfigSubsection
from config import ConfigSlider
from config import configSelection
from config import configSatlist

import xml.dom.minidom
from xml.dom import EMPTY_NAMESPACE
from skin import elementsWithTag
from Tools import XMLTools

from xml.sax import make_parser
from xml.sax.handler import ContentHandler

class boundFunction:
	def __init__(self, fnc, *args):
		self.fnc = fnc
		self.args = args
	def __call__(self, *args):
		self.fnc(*self.args + args)

class nimSlot:
	def __init__(self, slotid, nimtype, name):
		self.slotid = slotid
		self.nimType = nimtype
		self.name = name

class NimManager:
	class parseSats(ContentHandler):
		def __init__(self, satList, satellites):
			self.isPointsElement, self.isReboundsElement = 0, 0
			self.satList = satList
			self.satellites = satellites
	
		def startElement(self, name, attrs):
			if (name == "sat"):
				#print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
				tpos = attrs.get('position',"")
				tname = attrs.get('name',"")
				self.satellites[tpos] = tname
				self.satList.append( (tname, tpos) )

	def readSatsfromFile(self):
		self.satellites = { }

		#FIXME: path ok???
		print "Reading satellites.xml"
		parser = make_parser()
		satHandler = self.parseSats(self.satList, self.satellites)
		parser.setContentHandler(satHandler)
		parser.parse('/etc/tuxbox/satellites.xml')
    
		#satdom = xml.dom.minidom.parse('/etc/tuxbox/satellites.xml')


		#for entries in elementsWithTag(satdom.childNodes, "satellites"):
			#for x in elementsWithTag(entries.childNodes, "sat"):
				##print "found sat " + x.getAttribute('name') + " " + str(x.getAttribute('position'))
				#tpos = x.getAttribute('position')
				#tname = x.getAttribute('name')
				##tname.encode('utf8')
				#self.satellites[tpos] = tname
				#self.satList.append( (tname, tpos) )

	def getNimType(self, slotID):
		#FIXME get it from /proc
		if slotID == 0:
			return self.nimType["DVB-S"]
		else:
			return self.nimType["empty/unknown"]

	def getNimName(self, slotID):
		#FIXME get it from /proc
		return "Alps BSBE1"

	def getNimSocketCount(self):
		#FIXME get it from /proc
		return 2

	def getConfigPrefix(self, slotid):
		return "config.Nim" + ("A","B","C","D")[slotid] + "."
			
	def __init__(self):
		#use as enum
		self.nimType = {		"empty/unknown": -1,
												"DVB-S": 0,
												"DVB-C": 1,
												"DVB-T": 2}
		self.satList = [ ]										
												
		self.readSatsfromFile()										
												
		self.nimCount = self.getNimSocketCount()
		
		self.nimslots = [ ]
		x = 0
		while x < self.nimCount:
			tType = self.getNimType(x)
			tName = self.getNimName(x)
			tNim = nimSlot(x, tType, tName)
			self.nimslots.append(tNim)
			x += 1
		
		InitNimManager(self)	#init config stuff

	def nimList(self):
		list = [ ]
		for slot in self.nimslots:
			nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
			if slot.nimType == -1:
				nimText += "empty/unknown"
			else:
				nimText += slot.name + " ("	
				nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
			list.append((nimText, slot))
		return list

	#callbacks for c++ config
	def nimConfigModeChanged(self, slotid, mode):
		print "nimConfigModeChanged set to " + str(mode)
	def nimDiseqcModeChanged(self, slotid, mode):
		print "nimDiseqcModeChanged set to " + str(mode)
	def nimPortAChanged(self, slotid, val):
		print "nimDiseqcA set to " + str(val)
	def nimPortBChanged(self, slotid, val):
		print "nimDiseqcB set to " + str(val)
	def nimPortCChanged(self, slotid, val):
		print "nimDiseqcC set to " + str(val)
	def nimPortDChanged(self, slotid, val):
		print "nimDiseqcD set to " + str(val)


def InitNimManager(nimmgr):
	config.Nims = [ConfigSubsection()] * nimmgr.nimCount

	def nimConfigModeChanged(slotid, configElement):
		nimmgr.nimConfigModeChanged(slotid, configElement.value)
	def nimDiseqcModeChanged(slotid, configElement):
		nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
		
	def nimPortAChanged(slotid, configElement):
		nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
	def nimPortBChanged(slotid, configElement):
		nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
	def nimPortCChanged(slotid, configElement):
		nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
	def nimPortDChanged(slotid, configElement):
		nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])

	for slot in nimmgr.nimslots:
		x = slot.slotid
		cname = nimmgr.getConfigPrefix(x)
		
		if slot.nimType == nimmgr.nimType["DVB-S"]:
			config.Nims[x].configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
			config.Nims[x].diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D"));
			config.Nims[x].diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
			config.Nims[x].diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
			config.Nims[x].diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
			config.Nims[x].diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
			
			#perhaps the instance of the slot is more useful?
			config.Nims[x].configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
			config.Nims[x].diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
			config.Nims[x].diseqcA.addNotifier(boundFunction(nimPortAChanged,x))
			config.Nims[x].diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
			config.Nims[x].diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
			config.Nims[x].diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
		else:
			print "pls add support for this frontend type!"		

nimmanager = NimManager()