def doOpen(self, info, is_vuplusbox): if is_vuplusbox: self.mVuplusBox = is_vuplusbox self.mInfo = info return True document = "" try: document = os.popen(self.mCommand).read() except Exception as ErrMsg: vbcfg.ERR(ErrMsg) return False if len(document) == 0: return False document = re.sub(RE_XML_ILLEGAL, "?", document) document = re.sub("&", "+", document) document = re.sub("%", " ", document) document = document.decode("cp1252").encode("utf-8") document = "<URL>" + document + "</URL>" #print(document) try: self.mDocument = xml.dom.minidom.parseString(document) except Exception as ErrMsg: vbcfg.ERR("XML parse: %s" % ErrMsg) return False return True
def _CB_OOIF_GET_CURRENT_CHANNEL(self, result, packet): if (vbcfg.g_channel_info): try: data = struct.pack('iiii', vbcfg.g_channel_info[0], vbcfg.g_channel_info[1], vbcfg.g_channel_info[2], len(vbcfg.g_channel_info[3])) + vbcfg.g_channel_info[3] except Exception, err: vbcfg.ERR(err) return (False, None)
def SetHandler(opcode, handler): try: _OPCODE[opcode][1] = handler except: vbcfg.ERR("Fail to set handler (unknown opcode): %s" % opcode) return False return True
def start_application_selected(self, selected): vbcfg.DEBUG(selected) try: if selected[1] is not None: self._cb_hbbtv_activated(selected[1]["url"], selected[1]) except Exception as ErrMsg: vbcfg.ERR(ErrMsg)
def get_autostart_application(self): if self._applicationList is None: service = self.session.nav.getCurrentService() info = service and service.info() if info is not None: sid = info.getInfo(iServiceInformation.sSID) onid = info.getInfo(iServiceInformation.sONID) tsid = info.getInfo(iServiceInformation.sTSID) name = info.getName() vbcfg.g_channel_info = (sid, onid, tsid, name) pmtid = info.getInfo(iServiceInformation.sPMTPID) demux = info.getInfoString( iServiceInformation.sLiveStreamDemuxId) vbcfg.DEBUG("demux = %s, pmtid = 0x%x, sid = 0x%x" % (demux, pmtid, sid)) from aitreader import eAITSectionReader reader = eAITSectionReader(demux, pmtid, sid) if reader.doOpen(info, self.m_vuplus): reader.doParseApplications() #reader.doDump() else: vbcfg.ERR("no AIT") try: self._applicationList = reader.getApplicationList() except: pass if self._applicationList is not None: for app in self._applicationList: if app["control"] in (1, -1): return app return None
def unit_test(demux, pmtid, sid): reader = eAITSectionReader(demux, pmtid, sid) if reader.doOpen(): reader.doParseApplications() reader.doDump() else: vbcfg.ERR("no data!!")
def check_browser(self): try: ret = os.popen('%s/%s check' % (vbcfg.APPROOT, vbcfg.APP_RUN)).read() return ret.strip() != "0" except Exception as ErrMsg: vbcfg.ERR("check browser running: %s" % ErrMsg) return False
def _get(self, _section, _option, _default): try: data = self.mConfig.get(_section, _option) except Exception as e: vbcfg.ERR(e) return _default else: return data
def process(self, conn, addr): read_data = conn.recv(_BUFSIZE) request = self.parse(read_data) opcode, result, read_packet = request[0], request[1], request[2] result, send_packet = False, None try: result, send_packet = GetHandler(opcode)(result, read_packet) except Exception, ErrMsg: vbcfg.ERR(ErrMsg)
def doOpen(self, info, is_box): if is_box: self.mBox = is_box self.mInfo = info return True document = "" try: document = os.popen(self.mCommand).read() except Exception, ErrMsg: vbcfg.ERR(ErrMsg) return False
def _CB_GET_TIME_OFFSET(self, result, packet): time_struct = time.localtime() offset = (time_struct.tm_hour * 3600) + (time_struct.tm_min * 60) + time_struct.tm_sec try: data = struct.pack('i', int(offset)) except Exception, err: vbcfg.ERR(err) return (False, None)
def _CB_OOIF_GET_CURRENT_CHANNEL(self, result, packet): appinfo = vbcfg.g_main.get_autostart_application() orgid = appinfo and appinfo["orgid"] if (vbcfg.g_channel_info): try: data = struct.pack( 'iiiii', int(orgid), vbcfg.g_channel_info[0], vbcfg.g_channel_info[1], vbcfg.g_channel_info[2], len(vbcfg.g_channel_info[3])) + vbcfg.g_channel_info[3] except Exception, err: vbcfg.ERR(err) return (False, None)
def toggle_browser(self, selected): if selected is not None: if self.vbcallback: self.vbcallback() try: mode = selected[1] if mode == 'Start': if not self.check_browser(): self.start_browser() elif mode == 'Stop': self.stop_browser() except Exception as ErrMsg: vbcfg.ERR("toggle browser: %s" % ErrMsg)
def command(opcodestr, data=""): cmd_fd = None vbcfg.DEBUG("send ipc: [%s]" % opcodestr) try: send_data = VBController.assamble(opcodestr, data) if not os.path.exists(vbcfg.CONTROLFILE): raise Exception("no found controller file.") cmd_fd = os.open(vbcfg.CONTROLFILE, os.O_WRONLY) if cmd_fd is None: raise Exception("fail to open controller file.") os.write(cmd_fd, send_data) except Exception, err: vbcfg.ERR("VBHController: %s" % err) vbcfg.setPosition(vbcfg.g_position) vbcfg.osd_unlock() return False
def start_hbbtv_application(self): vbcfg.g_main.vbhandler.soft_volume = -1 self.setTitle(_('HbbTV Plugin')) vbcfg.LOG("Starting HbbTV") vbcfg.DEBUG("url : %s" % self._url and self._url) vbcfg.DEBUG("info: %s" % self._info and self._info) if self._info and self._info["control"] == 1 and vbcfg.g_channel_info is not None: (sid, onid, tsid, name) = vbcfg.g_channel_info params = struct.pack('iiiiii', 0, self._info["orgid"], sid, onid, tsid, 0) + vbcfg.g_channel_info[3] ret = VBController.command('HBBTV_LOADAIT', params) else: ret = VBController.command('HBBTV_OPENURL', self._url) if ret is False: self._close_timer.start(1000) vbcfg.ERR("Failed to start hbbtv")
def run(self): if self.mSock is None: raise self.mFlag = True self.mSock.listen(1) while self.mFlag: readable, writable, errored = select.select([self.mSock], [], [], self.mTimeout) for s in readable: if s is self.mSock: conn, addr = None, None try: conn, addr = self.mSock.accept() self.process(conn, addr) except Exception, err: vbcfg.ERR("VBSServerThread: %s" % err) finally: if conn is not None: conn.close()
def command(opcodestr, data=""): cmd_fd = None vbcfg.DEBUG("send ipc: [%s]" % opcodestr) try: send_data = VBController.assamble(opcodestr, data) if not os.path.exists(vbcfg.CONTROLFILE): raise Exception("no found controller file.") cmd_fd = os.open(vbcfg.CONTROLFILE, os.O_WRONLY) if cmd_fd is None: raise Exception("fail to open controller file.") os.write(cmd_fd, send_data) except Exception as err: vbcfg.ERR("VBHController: %s" % err) vbcfg.setPosition(vbcfg.g_position) fbClass.getInstance().unlock() eRCInput.getInstance().unlock() return False finally: if cmd_fd is not None: os.close(cmd_fd) return True
def _cb_start_browser(self, data=None, mode=0, opcode='BROWSER_OPENURL'): if not vbcfg.g_main.check_browser(): if self.m_url is not None: if vbcfg.g_service: self.session.nav.playService(vbcfg.g_service) return vbcfg.LOG("open url: %s %d" % (data, mode)) if strIsEmpty(data): return try: if self._cb_set_title not in vbcfg.g_main.vbhandler.onSetTitleCB: vbcfg.g_main.vbhandler.onSetTitleCB.append(self._cb_set_title) except Exception: pass try: if self._cb_close_window not in vbcfg.g_main.vbhandler.onCloseCB: vbcfg.g_main.vbhandler.onCloseCB.append(self._cb_close_window) except Exception: pass vbcfg.g_position = vbcfg.getPosition() fbClass.getInstance().lock() eRCInput.getInstance().lock() self.toggle_top() ret = VBController.command(opcode, data) self._current_url = data if ret: self.is_browser_opened = True else: self.is_browser_opened = False vbcfg.ERR("Failed to open url: %s" % data) vbcfg.g_main.vbhandler.soft_volume = -1
def do_command(self, command): try: self.COMMAND_MAP[command]() except Exception, ErrMsg: vbcfg.ERR(ErrMsg)
class eAITSectionReader: def __init__(self, demux, pmtid, sid): self.mVuplusBox = False self.mInfo = None self.mAppList = [] self.mDocument = None self.mCommand = "%s --demux=%s --pmtid=%x --serviceid=%x" % (DUMPBIN, demux, pmtid, sid) def __text(self, nodelist): rc = [] for node in nodelist: if node.nodeType == node.TEXT_NODE: rc.append(node.data) return ''.join(rc) def __item(self, application, name): for item in application.getElementsByTagName(name): return self.__text(item.childNodes) return None def __application(self, application): item = {} if self.mVuplusBox: item["name"] = str(application[1]) item["url"] = str(application[2]) item["control"] = int(application[0]) item["orgid"] = int(application[3]) item["appid"] = int(application[4]) item["profile"] = int(application[5]) else: item["name"] = str(self.__item(application, "name")) item["url"] = str(self.__item(application, "url")) item["control"] = int(self.__item(application, "control")) item["orgid"] = int(self.__item(application, "orgid")) item["appid"] = int(self.__item(application, "appid")) item["profile"] = int(self.__item(application, "profile")) #print item return item def doParseApplications(self): l = [] if self.mVuplusBox: for application in self.mInfo.getInfoObject(iServiceInformation.sHBBTVUrl): item = self.__application(application) l.append(item) else: for application in self.mDocument.getElementsByTagName("application"): item = self.__application(application) l.append(item) self.mAppList = l def getApplicationList(self): return self.mAppList def doOpen(self, info, is_vuplusbox): if is_vuplusbox: self.mVuplusBox = is_vuplusbox self.mInfo = info return True document = "" try: document = os.popen(self.mCommand).read() except Exception, ErrMsg: vbcfg.ERR(ErrMsg) return False if len(document) == 0: return False document = re.sub(RE_XML_ILLEGAL, "?", document) document = re.sub("&", "+", document) document = re.sub("%", " ", document) document = document.decode("cp1252").encode("utf-8") document = "<URL>" + document + "</URL>" #print document try: self.mDocument = xml.dom.minidom.parseString(document) except Exception, ErrMsg: vbcfg.ERR("XML parse: %s" % ErrMsg) return False