def toxmlNode(self, doc): node = doc.createElement("RPCData") node.appendChild(_setNode(doc, "TTSID", self.TTSID)) node.appendChild(_setNode(doc, "status", self.status)) if self.retval != None: rv = doc.createElement("retval") rv.appendChild(_setNode(doc, "execresult", self.retval.execResult.__str__())) tmp = doc.createElement("returnvalue") COMARValue._dump_value_xml(self.retval.returnValue, doc, tmp) rv.appendChild(tmp) node.appendChild(rv) return node
def initFromXml(self, xmlNode = None): if xmlNode == None: return None first = xmlNode.firstChild while first: if first.tagName == "type": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) if d in ["propertyget", "propertyset", "method"]: self.type = d else: return 1 elif first.tagName == "name": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) self.name = d[:255] elif first.tagName == "ttsid": if first.firstChild: d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) else: d = "" self.oldtts = d[:255] elif first.tagName == "index": if first.firstChild: d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) else: d = "" self.index = d elif first.tagName == "object": self.object = COMARValue._load_value_xml(first) print "OBJ:", self.object, self.object.type, self.object.data elif first.tagName == "parameters": # Difficult point.. node = first.firstChild while node: if node.tagName == "parameter": chld = node.firstChild prmname = None value = None while chld: if chld.tagName == "name": d = chld.firstChild.data[:].encode(COMARValue.GLO_ENCODING) prmname = d elif chld.tagName == "value": value = COMARValue._load_value_xml(chld.firstChild) chld=chld.nextSibling if prmname != None and value != None: self.prms[prmname] = value node = node.nextSibling first = first.nextSibling
def initFromXml(self, xmlNode = None): if xmlNode == None: return None first = xmlNode.firstChild rval = None res = None while first: if first.tagName == "TTSID": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) self.TTSID = d[:255] elif first.tagName == "status": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) if d in STATUS_CODES: self.status = d else: return 1 elif first.tagName == "retval": rvnode = first.firstChild while rvnode: if rvnode.tagName == "execresult": res = rvnode.firstChild.data[:].encode(COMARValue.GLO_ENCODING) elif rvnode.tagName == "returnvalue": tmp = rvnode.firstChild rval = COMARValue._load_value_xml(tmp) rvnode = rvnode.nextSibling first = first.nextSibling if rval != None and res != None: if self.status == "RESULT": self.retval = COMARValue.COMARRetVal(result = int(res), value = rval)
def toxmlNode(self, doc): node = doc.createElement("RPCData") node.appendChild(_setNode(doc, "type", self.type)) node.appendChild(_setNode(doc, "name", self.name)) node.appendChild(_setNode(doc, "index", self.index)) prms = doc.createElement("parameters") k = self.prms.keys() for i in k: #print "KEY: ", i, "Value:", self.prms[i] tnode = doc.createElement("parameter") tnode.appendChild(_setNode(doc, "name", i.__str__())) vnode = doc.createElement("value") COMARValue._dump_value_xml(self.prms[i], doc, vnode) tnode.appendChild(vnode) prms.appendChild(tnode) node.appendChild(prms) return node
def status(self): tts = createttsid(scope = "HOST") R = RPCData.RPCStruct() R.TTSID = "_TTSGEN_" R.makeRPCData("RESPONSE") R["status"] = "RESULT" R["TTSID"] = R.TTSID R["returnvalue"] = COMARValue.COMARRetVal(result = 0, value = COMARValue.string_create(tts)) return R
def loadValue(self, name = "", mode = 'instance', callerInfo = None, profile = None): dbpath = self.getDBFileKey(mode, callerInfo) dbkey = dbpath + name try: dbfile = open(dbkey, 'r') except: return COMARValue.COMARValue("null") xml = dbfile.read() return COMARValue.load_value_xml(xml)
def _testPipe(cmd="TRSU_CKTA", data="serdar"): p = COMARPipe() x = os.fork() if x: p.initFor("parent") print "Parent: send bytes:" data = COMARValue.string_create("Ben bir stringim") ps = p.putCommand(cmd, 109, 159, cPickle.dumps(data)) print "PARENT PUT:", ps st = "" os.wait() else: p.initFor("child") select.select([p.cmd_rfile], [], [], 10) cmd = p.getCommand() print "Command:", cmd value = cmd[3] cv = cPickle.loads(value) print "CHILD: CV =", cv, "CVS=", COMARValue.dump_value_xml(cv) sys.exit(1)
def initFromXml(self, xmlNode = None): if xmlNode == None: return None first = xmlNode.firstChild while first: if first.tagName == "type": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) if d in ["propertyget", "propertyset", "method"]: self.type = d else: return 1 elif first.tagName == "name": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) self.name = d[:255] elif first.tagName == "index": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) self.index = d[:255] elif first.tagName == "code": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) self.code = d[:65535] elif first.tagName == "compression": d = first.firstChild.data[:].encode(COMARValue.GLO_ENCODING) self._compress = d elif first.tagName == "parameters": # Difficult point.. node = first.firstChild while node: if node.tagName == "parameter": chld = node.firstChild prmname = None value = None while chld: if chld.tagName == "name": d = chld.firstChild.data[:].encode(COMARValue.GLO_ENCODING) prmname = d elif chld.tagName == "value": value = COMARValue._load_value_xml(chld.firstChild) chld=chld.nextSibling if prmname != None and value != None: self.prms[prmname] = value node = node.nextSibling first = first.nextSibling if self._compress == "GZIP": self.code = base64.decodestring(self.code) self.code = zlib.decompress(self.code) elif self._compress == "BZIP2": self.code = base64.decodestring(self.code) self.code = bz2.decompress(self.code) elif self._compress != "NONE": return 1
def saveValue(self, name = "", value = None, mode = 'instance', callerInfo = None, profile = None): """ Save a persistent value to object storage """ # We can use a hash db, SQL DB etc. # But current debug requirements # require a simple format. if profile: pass dbpath = self.getDBFileKey(mode, callerInfo) dbkey = dbpath + name dbfile = open(dbkey, 'w') dbfile.write(COMARValue.dump_value_xml(value)) dbfile.close()
def start(): """Starts COMARd""" global CONNS, AUTHHELPER cv = COMARValue print "Initializing COMARd-client" if os.getuid(): print "Only root can be use this program\nExiting.." os._exit(1) AUTHHELPER = AUTHSYS.authSystem() CONNS = ConnectorModules() HTTP = CONNS.getModule("cxdrpc-http").object(comarHelper = comarRoot()) rpc = RPCData.RPCStruct() op = "call" cslfile = "csl/sample/xorg.csl" omnode = "COMAR:Boot" appid = "DENEME" callEntry = "COMAR:Boot.ConfigureDisplay" callProperty = None propVal = None remoteHost = "127.0.0.1:8000" objid = "test" objttsid = "TEST_03" + str(time.time()) callttsid = "TEST_02" + str(time.time()) prml = {} x = 0 skip = 0 for i in sys.argv: if skip: skip = 0 elif i == "--help": print """ COMARd Test Client v 0.0.1 Usage: for register a CSL file to OM: testclient.py --register [--file file][--node omnode][--appid appid] filename = Filename for CSL Code. Default: $PWD/csl/sample/xorg.csl node = OM Node for bind. Default: COMAR:Boot appid = Application ID. Default: DENEME for call OM Method Entry: testclient.py [--method methodName] | [--property propertyName [--setprop value]] method = Name of Method. Default: "COMAR:Boot.ConfigureDisplay" property = Name of Property, force Property read callEntry setprop = New value for Property. Global Parameters: --parameter prm=val Add parameter "prm" with value "val" to call. --host ipAddr:port Host address for required COMARd daemon.. --objtest objid OBJCALL Mode.. --objttsid ttsid TTSID for Object.. """ os._exit(0) elif i == "--register": op = "register" elif i == "--objtest": op = "objcall" objid = sys.argv[x+1] if callEntry == "COMAR:Boot.ConfigureDisplay": callEntry = "testEntry" skip = 1 elif i == "--node": omnode = sys.argv[x+1] skip = 1 elif i == "--appid": appid = sys.argv[x+1] skip = 1 elif i == "--method": callEntry = sys.argv[x+1] skip = 1 elif i == "--property": callProperty = sys.argv[x+1] skip = 1 elif i == "--setprop": pval = sys.argv[x+1] try: pval = int(pval) propVal = COMARValue.numeric_create(pval) except: propVal = COMARValue.string_create(pval) skip = 1 elif i == "--host": remoteHost = sys.argv[x+1] skip = 1 elif i == "--ttsid": callttsid = sys.argv[x+1] skip = 1 elif i == "--objttsid": objttsid = sys.argv[x+1] skip = 1 elif i == "--parameter": j = sys.argv[x+1] skip = 1 print j key = j.split("=")[0] val = j.split("=")[1] print "Parameter '%s' value: %s" % (key, val) try: val = int(val) cval = COMARValue.numeric_create(val) except: cval = COMARValue.string_create(val) prml[key] = cval elif i == "--file": cslfile = sys.argv[x+1] skip = 1 x += 1 if op == "register": rpc.TTSID = callttsid rpc.RPCPriority = "INTERACTIVE" rpc.makeRPCData("OMCALL") rpc["name"] = "CORE:om.addNodeScript" rpc["type"] = "method" fname = cv.string_create(os.path.basename(cslfile)) appid = cv.string_create(appid) f = open(cslfile) code = cv.string_create(f.read()) f.close() node = cv.string_create(omnode) rpc.addPropertyMulti("parameter", "fileName", fname) rpc.addPropertyMulti("parameter", "code", code) rpc.addPropertyMulti("parameter", "AppID", appid) rpc.addPropertyMulti("parameter", "node", node) elif op == "objcall": rpc.TTSID = callttsid rpc.RPCPriority = "INTERACTIVE" rpc.makeRPCData("OBJCALL") print "Setting OBJ TTSID:", rpc["ttsid"] = objttsid print rpc["ttsid"] rpc["object"] = cv.COMARValue(type="object", data = objid) if callProperty: rpc["name"] = callProperty rpc.addPropertyMulti("parameter", "index", propindex) if propVal: rpc["type"] = "propertyset" rpc.addPropertyMulti("parameter", "value", propVal) else: rpc["type"] = "propertyget" else: rpc["name"] = callEntry rpc["type"] = "method" else: rpc.TTSID = callttsid rpc.RPCPriority = "INTERACTIVE" rpc.makeRPCData("OMCALL") if callProperty: rpc["name"] = callProperty if propVal: rpc["type"] = "propertyset" else: rpc["type"] = "propertyget" else: rpc["name"] = callEntry rpc["type"] = "method" for key in prml.keys(): print "ADD PRM:", key, prml[key], rpc.addPropertyMulti("parameter", key, prml[key]) print "Send HTTP to localhost from:", os.getpid(), time.time(), rpc.xml print HTTP.makeConnection(realmAddress = remoteHost) HTTP.sendRPC(rpc = rpc)