summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2009-09-02 14:32:57 +0000
committerTed Ross <tross@apache.org>2009-09-02 14:32:57 +0000
commit4ab8745255dad1cfaf3f69f782d721ace36ff0fc (patch)
tree26246ccf90628c72984a67d4cae3d02d3c27f00e
parent1dc24b76364878a9c9dde3ad3b7dbc2b85567c68 (diff)
downloadqpid-python-4ab8745255dad1cfaf3f69f782d721ace36ff0fc.tar.gz
QPID-2064 - add python bindings for qmf (c++)
Applied patch from Ken Giusti git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@810523 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--cpp/bindings/qmf/Makefile.am2
-rw-r--r--cpp/bindings/qmf/python/Makefile.am6
-rw-r--r--cpp/bindings/qmf/python/python.i120
-rw-r--r--cpp/bindings/qmf/python/qmf.py854
-rw-r--r--cpp/bindings/qmf/tests/python_agent.py192
-rwxr-xr-xcpp/bindings/qmf/tests/run_interop_tests32
-rw-r--r--cpp/configure.ac1
-rw-r--r--cpp/src/qmf/AgentEngine.h2
-rw-r--r--cpp/src/qmf/Value.h2
9 files changed, 1198 insertions, 13 deletions
diff --git a/cpp/bindings/qmf/Makefile.am b/cpp/bindings/qmf/Makefile.am
index 897f744b94..9637c319f0 100644
--- a/cpp/bindings/qmf/Makefile.am
+++ b/cpp/bindings/qmf/Makefile.am
@@ -21,7 +21,7 @@ if HAVE_SWIG
if HAVE_RUBY_DEVEL
EXTRA_DIST = qmfengine.i
-SUBDIRS = ruby tests
+SUBDIRS = ruby python tests
endif
endif
diff --git a/cpp/bindings/qmf/python/Makefile.am b/cpp/bindings/qmf/python/Makefile.am
index 7b3f4d3be7..e7f5ff53e1 100644
--- a/cpp/bindings/qmf/python/Makefile.am
+++ b/cpp/bindings/qmf/python/Makefile.am
@@ -35,8 +35,10 @@ pylibdir = $(PYTHON_LIB)
lib_LTLIBRARIES = _qmfengine.la
-_qmfengine_la_LDFLAGS = -avoid-version -module -shrext "$(PYTHON_SO)"
-_qmfengine_la_LIBADD = $(PYTHON_LIBS) -L$(top_builddir)/src/.libs -lqpidclient $(top_builddir)/src/libqmfcommon.la
+#_qmfengine_la_LDFLAGS = -avoid-version -module -shrext "$(PYTHON_SO)"
+#_qmfengine_la_LDFLAGS = -avoid-version -module -shrext ".so"
+_qmfengine_la_LDFLAGS = -avoid-version -module -shared
+_qmfengine_la_LIBADD = $(PYTHON_LIBS) -L$(top_builddir)/src/.libs -lqpidclient $(top_builddir)/src/libqmfagent.la
_qmfengine_la_CXXFLAGS = $(INCLUDES) -I$(srcdir)/qmf -I$(PYTHON_INC)
_qmfengine_la_SOURCES = \
qmfengine.cpp
diff --git a/cpp/bindings/qmf/python/python.i b/cpp/bindings/qmf/python/python.i
index ea14efd4dd..5e25d155f9 100644
--- a/cpp/bindings/qmf/python/python.i
+++ b/cpp/bindings/qmf/python/python.i
@@ -19,17 +19,125 @@
%module qmfengine
-// These are probably wrong.. just to get it to compile for now.
-%typemap (in) void *
-{
- $1 = (void *) $input;
+
+/* unsigned32 Convert from Python --> C */
+%typemap(in) uint32_t {
+ if (PyInt_Check($input)) {
+ $1 = (uint32_t) PyInt_AsUnsignedLongMask($input);
+ } else if (PyLong_Check($input)) {
+ $1 = (uint32_t) PyLong_AsUnsignedLong($input);
+ } else {
+ SWIG_exception_fail(SWIG_ValueError, "unknown integer type");
+ }
+}
+
+/* unsinged32 Convert from C --> Python */
+%typemap(out) uint32_t {
+ $result = PyInt_FromLong((long)$1);
+}
+
+
+/* unsigned16 Convert from Python --> C */
+%typemap(in) uint16_t {
+ if (PyInt_Check($input)) {
+ $1 = (uint16_t) PyInt_AsUnsignedLongMask($input);
+ } else if (PyLong_Check($input)) {
+ $1 = (uint16_t) PyLong_AsUnsignedLong($input);
+ } else {
+ SWIG_exception_fail(SWIG_ValueError, "unknown integer type");
+ }
+}
+
+/* unsigned16 Convert from C --> Python */
+%typemap(out) uint16_t {
+ $result = PyInt_FromLong((long)$1);
+}
+
+
+/* signed32 Convert from Python --> C */
+%typemap(in) int32_t {
+ if (PyInt_Check($input)) {
+ $1 = (int32_t) PyInt_AsLong($input);
+ } else if (PyLong_Check($input)) {
+ $1 = (int32_t) PyLong_AsLong($input);
+ } else {
+ SWIG_exception_fail(SWIG_ValueError, "unknown integer type");
+ }
+}
+
+/* signed32 Convert from C --> Python */
+%typemap(out) int32_t {
+ $result = PyInt_FromLong((long)$1);
+}
+
+
+/* unsigned64 Convert from Python --> C */
+%typemap(in) uint64_t {
+%#ifdef HAVE_LONG_LONG
+ if (PyLong_Check($input)) {
+ $1 = (uint64_t)PyLong_AsUnsignedLongLong($input);
+ } else if (PyInt_Check($input)) {
+ $1 = (uint64_t)PyInt_AsUnsignedLongLongMask($input);
+ } else
+%#endif
+ {
+ SWIG_exception_fail(SWIG_ValueError, "unsupported integer size - uint64_t input too large");
+ }
+}
+
+/* unsigned64 Convert from C --> Python */
+%typemap(out) uint64_t {
+%#ifdef HAVE_LONG_LONG
+ $result = PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)$1);
+%#else
+ SWIG_exception_fail(SWIG_ValueError, "unsupported integer size - uint64_t output too large");
+%#endif
+}
+
+/* signed64 Convert from Python --> C */
+%typemap(in) int64_t {
+%#ifdef HAVE_LONG_LONG
+ if (PyLong_Check($input)) {
+ $1 = (int64_t)PyLong_AsLongLong($input);
+ } else if (PyInt_Check($input)) {
+ $1 = (int64_t)PyInt_AsLong($input);
+ } else
+%#endif
+ {
+ SWIG_exception_fail(SWIG_ValueError, "unsupported integer size - int64_t input too large");
+ }
+}
+
+/* signed64 Convert from C --> Python */
+%typemap(out) int64_t {
+%#ifdef HAVE_LONG_LONG
+ $result = PyLong_FromLongLong((PY_LONG_LONG)$1);
+%#else
+ SWIG_exception_fail(SWIG_ValueError, "unsupported integer size - int64_t output too large");
+%#endif
}
-%typemap (out) void *
-{
+
+/* Convert from Python --> C */
+%typemap(in) void * {
+ $1 = (void *)$input;
+}
+
+/* Convert from C --> Python */
+%typemap(out) void * {
$result = (PyObject *) $1;
+ Py_INCREF($result);
+}
+
+%typemap (typecheck, precedence=SWIG_TYPECHECK_UINT64) uint64_t {
+ $1 = PyLong_Check($input) ? 1 : 0;
}
+%typemap (typecheck, precedence=SWIG_TYPECHECK_UINT32) uint32_t {
+ $1 = PyInt_Check($input) ? 1 : 0;
+}
+
+
%include "../qmfengine.i"
diff --git a/cpp/bindings/qmf/python/qmf.py b/cpp/bindings/qmf/python/qmf.py
new file mode 100644
index 0000000000..265f204852
--- /dev/null
+++ b/cpp/bindings/qmf/python/qmf.py
@@ -0,0 +1,854 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import sys
+import socket
+import os
+from threading import Thread
+from threading import RLock
+import qmfengine
+from qmfengine import (ACCESS_READ_CREATE, ACCESS_READ_ONLY, ACCESS_READ_WRITE)
+from qmfengine import (CLASS_EVENT, CLASS_OBJECT)
+from qmfengine import (DIR_IN, DIR_IN_OUT, DIR_OUT)
+from qmfengine import (TYPE_ABSTIME, TYPE_ARRAY, TYPE_BOOL, TYPE_DELTATIME,
+ TYPE_DOUBLE, TYPE_FLOAT, TYPE_INT16, TYPE_INT32, TYPE_INT64,
+ TYPE_INT8, TYPE_LIST, TYPE_LSTR, TYPE_MAP, TYPE_OBJECT,
+ TYPE_REF, TYPE_SSTR, TYPE_UINT16, TYPE_UINT32, TYPE_UINT64,
+ TYPE_UINT8, TYPE_UUID)
+
+
+ ##==============================================================================
+ ## CONNECTION
+ ##==============================================================================
+
+class ConnectionSettings:
+ #attr_reader :impl
+ def __init__(self, url=None):
+ if url:
+ self.impl = qmfengine.ConnectionSettings(url)
+ else:
+ self.impl = qmfengine.ConnectionSettings()
+
+
+ def set_attr(self, key, val):
+ if type(val) == str:
+ _v = qmfengine.Value(TYPE_LSTR)
+ _v.setString(val)
+ elif type(val) == bool:
+ _v = qmfengine.Value(TYPE_BOOL)
+ _v.setBool(val)
+ elif type(val) == int:
+ _v = qmfengine.Value(TYPE_UINT32)
+ _v.setUint(val)
+ else:
+ raise ArgumentError("Value for attribute '%s' has unsupported type: %s" % ( key, type(val)))
+
+ self.impl.setAttr(key, _v)
+
+
+
+class ConnectionHandler:
+ def conn_event_connected(self): None
+ def conn_event_disconnected(self, error): None
+ def sess_event_session_closed(self, context, error): None
+ def sess_event_recv(self, context, message): None
+
+
+
+class Connection(Thread):
+ def __init__(self, settings):
+ Thread.__init__(self)
+ self._lock = RLock()
+ self.impl = qmfengine.ResilientConnection(settings.impl)
+ self._sockEngine, self._sock = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+ self.impl.setNotifyFd(self._sockEngine.fileno())
+ self._new_conn_handlers = []
+ self._conn_handlers = []
+ self.start()
+
+
+ def add_conn_handler(self, handler):
+ self._lock.acquire()
+ try:
+ self._new_conn_handlers.append(handler)
+ finally:
+ self._lock.release()
+ self._sockEngine.send("x")
+
+
+ def run(self):
+ eventImpl = qmfengine.ResilientConnectionEvent()
+ connected = False
+ new_handlers = []
+ bt_count = 0
+
+ while True:
+ # print "Waiting for socket data"
+ self._sock.recv(1)
+
+ self._lock.acquire()
+ try:
+ new_handlers = self._new_conn_handlers
+ self._new_conn_handlers = []
+ finally:
+ self._lock.release()
+
+ for nh in new_handlers:
+ self._conn_handlers.append(nh)
+ if connected:
+ nh.conn_event_connected()
+
+ new_handlers = []
+
+ valid = self.impl.getEvent(eventImpl)
+ while valid:
+ try:
+ if eventImpl.kind == qmfengine.ResilientConnectionEvent.CONNECTED:
+ connected = True
+ for h in self._conn_handlers:
+ h.conn_event_connected()
+
+ elif eventImpl.kind == qmfengine.ResilientConnectionEvent.DISCONNECTED:
+ connected = False
+ for h in self._conn_handlers:
+ h.conn_event_disconnected(eventImpl.errorText)
+
+ elif eventImpl.kind == qmfengine.ResilientConnectionEvent.SESSION_CLOSED:
+ eventImpl.sessionContext.handler.sess_event_session_closed(eventImpl.sessionContext, eventImpl.errorText)
+
+ elif eventImpl.kind == qmfengine.ResilientConnectionEvent.RECV:
+ eventImpl.sessionContext.handler.sess_event_recv(eventImpl.sessionContext, eventImpl.message)
+
+ except:
+ import traceback
+ print "Event Exception:", sys.exc_info()
+ if bt_count < 2:
+ traceback.print_exc()
+ traceback.print_stack()
+ bt_count += 1
+
+ self.impl.popEvent()
+ valid = self.impl.getEvent(eventImpl)
+
+
+
+class Session:
+ def __init__(self, conn, label, handler):
+ self._conn = conn
+ self._label = label
+ self.handler = handler
+ self.handle = qmfengine.SessionHandle()
+ result = self._conn.impl.createSession(label, self, self.handle)
+
+
+ def __del__(self):
+ self._conn.impl.destroySession(self.handle)
+
+
+
+ ##==============================================================================
+ ## OBJECTS
+ ##==============================================================================
+
+class QmfObject:
+ # attr_reader :impl, :object_class
+ def __init__(self, cls):
+ self.object_class = cls
+ self.impl = qmfengine.Object(self.object_class.impl)
+
+
+ def __del__(self):
+ self.impl.destroy()
+
+
+ def object_id(self):
+ return ObjectId(self.impl.getObjectId())
+
+
+ def set_object_id(self, oid):
+ self.impl.setObjectId(oid.impl)
+
+
+ def get_attr(self, name):
+ val = self._value(name)
+ vType = val.getType()
+ if vType == TYPE_UINT8: return val.asUint()
+ elif vType == TYPE_UINT16: return val.asUint()
+ elif vType == TYPE_UINT32: return val.asUint()
+ elif vType == TYPE_UINT64: return val.asUint64()
+ elif vType == TYPE_SSTR: return val.asString()
+ elif vType == TYPE_LSTR: return val.asString()
+ elif vType == TYPE_ABSTIME: return val.asInt64()
+ elif vType == TYPE_DELTATIME: return val.asUint64()
+ elif vType == TYPE_REF: return val.asObjectId()
+ elif vType == TYPE_BOOL: return val.asBool()
+ elif vType == TYPE_FLOAT: return val.asFloat()
+ elif vType == TYPE_DOUBLE: return val.asDouble()
+ elif vType == TYPE_UUID: return val.asUuid()
+ elif vType == TYPE_INT8: return val.asInt()
+ elif vType == TYPE_INT16: return val.asInt()
+ elif vType == TYPE_INT32: return val.asInt()
+ elif vType == TYPE_INT64: return val.asInt64()
+ else:
+ # when TYPE_MAP
+ # when TYPE_OBJECT
+ # when TYPE_LIST
+ # when TYPE_ARRAY
+ print "Unsupported type for get_attr?", val.getType()
+ return None
+
+
+ def set_attr(self, name, v):
+ val = self._value(name)
+ vType = val.getType()
+ if vType == TYPE_UINT8: return val.setUint(v)
+ elif vType == TYPE_UINT16: return val.setUint(v)
+ elif vType == TYPE_UINT32: return val.setUint(v)
+ elif vType == TYPE_UINT64: return val.setUint64(v)
+ elif vType == TYPE_SSTR:
+ if v: return val.setString(v)
+ else: return val.setString('')
+ elif vType == TYPE_LSTR:
+ if v: return val.setString(v)
+ else: return val.setString('')
+ elif vType == TYPE_ABSTIME: return val.setInt64(v)
+ elif vType == TYPE_DELTATIME: return val.setUint64(v)
+ elif vType == TYPE_REF: return val.setObjectId(v.impl)
+ elif vType == TYPE_BOOL: return val.setBool(v)
+ elif vType == TYPE_FLOAT: return val.setFloat(v)
+ elif vType == TYPE_DOUBLE: return val.setDouble(v)
+ elif vType == TYPE_UUID: return val.setUuid(v)
+ elif vType == TYPE_INT8: return val.setInt(v)
+ elif vType == TYPE_INT16: return val.setInt(v)
+ elif vType == TYPE_INT32: return val.setInt(v)
+ elif vType == TYPE_INT64: return val.setInt64(v)
+ else:
+ # when TYPE_MAP
+ # when TYPE_OBJECT
+ # when TYPE_LIST
+ # when TYPE_ARRAY
+ print "Unsupported type for get_attr?", val.getType()
+ return None
+
+
+ def __getitem__(self, name):
+ return self.get_attr(name)
+
+
+ def __setitem__(self, name, value):
+ self.set_attr(name, value)
+
+
+ def inc_attr(self, name, by=1):
+ self.set_attr(name, self.get_attr(name) + by)
+
+
+ def dec_attr(self, name, by=1):
+ self.set_attr(name, self.get_attr(name) - by)
+
+
+ def _value(self, name):
+ val = self.impl.getValue(name)
+ if not val:
+ raise ArgumentError("Attribute '%s' not defined for class %s" % (name, self.object_class.impl.getName()))
+ return val
+
+
+
+class ConsoleObject(QmfObject):
+ # attr_reader :current_time, :create_time, :delete_time
+ def __init__(self, cls):
+ QmfObject.__init__(self, cls)
+
+
+ def update(self): pass
+ def mergeUpdate(self, newObject): pass
+ def is_deleted(self):
+ return self.delete_time > 0
+ def index(self): pass
+ def method_missing(self, name, *args): pass
+
+
+
+class ObjectId:
+ def __init__(self, impl=None):
+ if impl:
+ self.impl = impl
+ else:
+ self.impl = qmfengine.ObjectId()
+
+
+ def object_num_high(self):
+ return self.impl.getObjectNumHi()
+
+
+ def object_num_low(self):
+ return self.impl.getObjectNumLo()
+
+
+ def __eq__(self, other):
+ if self.__class__ != other.__class__: return False
+ return (self.impl.getObjectNumHi() == other.impl.getObjectNumHi() and
+ self.impl.getObjectNumLo() == other.impl.getObjectNumLo())
+
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+
+
+class Arguments:
+ def __init__(self, map):
+ self.map = map
+ self._by_hash = {}
+ key_count = self.map.keyCount()
+ a = 0
+ while a < key_count:
+ self._by_hash[self.map.key(a)] = self.by_key(self.map.key(a))
+ a += 1
+
+
+ def __getitem__(self, key):
+ return self._by_hash[key]
+
+
+ def __setitem__(self, key, value):
+ self._by_hash[key] = value
+ self.set(key, value)
+
+
+ def __iter__(self):
+ return _by_hash.__iter__
+
+
+ def by_key(self, key):
+ val = self.map.byKey(key)
+ vType = val.getType()
+ if vType == TYPE_UINT8: return val.asUint()
+ elif vType == TYPE_UINT16: return val.asUint()
+ elif vType == TYPE_UINT32: return val.asUint()
+ elif vType == TYPE_UINT64: return val.asUint64()
+ elif vType == TYPE_SSTR: return val.asString()
+ elif vType == TYPE_LSTR: return val.asString()
+ elif vType == TYPE_ABSTIME: return val.asInt64()
+ elif vType == TYPE_DELTATIME: return val.asUint64()
+ elif vType == TYPE_REF: return val.asObjectId()
+ elif vType == TYPE_BOOL: return val.asBool()
+ elif vType == TYPE_FLOAT: return val.asFloat()
+ elif vType == TYPE_DOUBLE: return val.asDouble()
+ elif vType == TYPE_UUID: return val.asUuid()
+ elif vType == TYPE_INT8: return val.asInt()
+ elif vType == TYPE_INT16: return val.asInt()
+ elif vType == TYPE_INT32: return val.asInt()
+ elif vType == TYPE_INT64: return val.asInt64()
+ else:
+ # when TYPE_MAP
+ # when TYPE_OBJECT
+ # when TYPE_LIST
+ # when TYPE_ARRAY
+ print "Unsupported Type for Get?", val.getType()
+ return None
+
+
+ def set(self, key, value):
+ val = self.map.byKey(key)
+ vType = val.getType()
+ if vType == TYPE_UINT8: return val.setUint(value)
+ elif vType == TYPE_UINT16: return val.setUint(value)
+ elif vType == TYPE_UINT32: return val.setUint(value)
+ elif vType == TYPE_UINT64: return val.setUint64(value)
+ elif vType == TYPE_SSTR:
+ if value:
+ return val.setString(value)
+ else:
+ return val.setString('')
+ elif vType == TYPE_LSTR:
+ if value:
+ return val.setString(value)
+ else:
+ return val.setString('')
+ elif vType == TYPE_ABSTIME: return val.setInt64(value)
+ elif vType == TYPE_DELTATIME: return val.setUint64(value)
+ elif vType == TYPE_REF: return val.setObjectId(value.impl)
+ elif vType == TYPE_BOOL: return val.setBool(value)
+ elif vType == TYPE_FLOAT: return val.setFloat(value)
+ elif vType == TYPE_DOUBLE: return val.setDouble(value)
+ elif vType == TYPE_UUID: return val.setUuid(value)
+ elif vType == TYPE_INT8: return val.setInt(value)
+ elif vType == TYPE_INT16: return val.setInt(value)
+ elif vType == TYPE_INT32: return val.setInt(value)
+ elif vType == TYPE_INT64: return val.setInt64(value)
+ else:
+ # when TYPE_MAP
+ # when TYPE_OBJECT
+ # when TYPE_LIST
+ # when TYPE_ARRAY
+ print "Unsupported Type for Set?", val.getType()
+ return None
+
+
+
+class Query:
+ def __init__(self, i=None):
+ if i:
+ self.impl = i
+ else:
+ self.impl = qmfengine.Query()
+
+
+ def package_name(self): return self.impl.getPackage()
+ def class_name(self): return self.impl.getClass()
+ def object_id(self):
+ _objid = self.impl.getObjectId()
+ if _objid:
+ return ObjectId(_objid)
+ else:
+ return None
+ OPER_AND = qmfengine.Query.OPER_AND
+ OPER_OR = qmfengine.Query.OPER_OR
+
+
+
+ ##==============================================================================
+ ## SCHEMA
+ ##==============================================================================
+
+
+
+class SchemaArgument:
+ #attr_reader :impl
+ def __init__(self, name, typecode, kwargs={}):
+ self.impl = qmfengine.SchemaArgument(name, typecode)
+ if kwargs.has_key("dir"): self.impl.setDirection(kwargs["dir"])
+ if kwargs.has_key("unit"): self.impl.setUnit(kwargs["unit"])
+ if kwargs.has_key("desc"): self.impl.setDesc(kwargs["desc"])
+
+
+
+class SchemaMethod:
+ # attr_reader :impl
+ def __init__(self, name, kwargs={}):
+ self.impl = qmfengine.SchemaMethod(name)
+ if kwargs.has_key("desc"): self.impl.setDesc(kwargs["desc"])
+ self._arguments = []
+
+
+ def add_argument(self, arg):
+ self._arguments.append(arg)
+ self.impl.addArgument(arg.impl)
+
+
+class SchemaProperty:
+ #attr_reader :impl
+ def __init__(self, name, typecode, kwargs={}):
+ self.impl = qmfengine.SchemaProperty(name, typecode)
+ if kwargs.has_key("access"): self.impl.setAccess(kwargs["access"])
+ if kwargs.has_key("index"): self.impl.setIndex(kwargs["index"])
+ if kwargs.has_key("optional"): self.impl.setOptional(kwargs["optional"])
+ if kwargs.has_key("unit"): self.impl.setUnit(kwargs["unit"])
+ if kwargs.has_key("desc"): self.impl.setDesc(kwargs["desc"])
+
+
+ def name(self):
+ return self.impl.getName()
+
+
+
+class SchemaStatistic:
+ # attr_reader :impl
+ def __init__(self, name, typecode, kwargs={}):
+ self.impl = qmfengine.SchemaStatistic(name, typecode)
+ if kwargs.has_key("unit"): self.impl.setUnit(kwargs["unit"])
+ if kwargs.has_key("desc"): self.impl.setDesc(kwargs["desc"])
+
+
+
+class SchemaClassKey:
+ #attr_reader :impl
+ def __init__(self, i):
+ self.impl = i
+
+
+ def get_package(self):
+ self.impl.getPackageName()
+
+
+ def get_class(self):
+ self.impl.getClassName()
+
+
+
+class SchemaObjectClass:
+ # attr_reader :impl
+ def __init__(self, package, name, kwargs={}):
+ self.impl = qmfengine.SchemaObjectClass(package, name)
+ self._properties = []
+ self._statistics = []
+ self._methods = []
+
+
+ def add_property(self, prop):
+ self._properties.append(prop)
+ self.impl.addProperty(prop.impl)
+
+
+ def add_statistic(self, stat):
+ self._statistics.append(stat)
+ self.impl.addStatistic(stat.impl)
+
+
+ def add_method(self, meth):
+ self._methods.append(meth)
+ self.impl.addMethod(meth.impl)
+
+
+ def name(self):
+ return self.impl.getName()
+
+
+ def properties(self):
+ return self._properties
+
+
+class SchemaEventClass:
+ # attr_reader :impl
+ def __init__(self, package, name, kwargs={}):
+ self.impl = qmfengine.SchemaEventClass(package, name)
+ if kwargs.has_key("desc"): self.impl.setDesc(kwargs["desc"])
+ self._arguments = []
+
+
+ def add_argument(self, arg):
+ self._arguments.append(arg)
+ self.impl.addArgument(arg.impl)
+
+
+
+ ##==============================================================================
+ ## CONSOLE
+ ##==============================================================================
+
+
+
+class ConsoleHandler:
+ def agent_added(self, agent): pass
+ def agent_deleted(self, agent): pass
+ def new_package(self, package): pass
+ def new_class(self, class_key): pass
+ def object_update(self, obj, hasProps, hasStats): pass
+ def event_received(self, event): pass
+ def agent_heartbeat(self, agent, timestamp): pass
+ def method_response(self, resp): pass
+ def broker_info(self, broker): pass
+
+
+
+class Console:
+ # attr_reader :impl
+ def initialize(handler=None, kwargs={}):
+ self._handler = handler
+ self.impl = qmfengine.ConsoleEngine()
+ self._event = qmfengine.ConsoleEvent()
+ self._broker_list = []
+
+
+ def add_connection(self, conn):
+ broker = Broker(self, conn)
+ self._broker_list.append(broker)
+ return broker
+
+
+ def del_connection(self, broker): pass
+
+
+ def get_packages(self): pass
+
+
+ def get_classes(self, package): pass
+
+
+ def get_schema(self, class_key): pass
+
+
+ def bind_package(self, package): pass
+
+
+ def bind_class(self, kwargs = {}): pass
+
+
+ def get_agents(self, broker=None): pass
+
+
+ def get_objects(self, query, kwargs = {}): pass
+
+
+ def start_sync(self, query): pass
+
+
+ def touch_sync(self, sync): pass
+
+
+ def end_sync(self, sync): pass
+
+
+ def do_console_events(self):
+ count = 0
+ valid = self.impl.getEvent(self._event)
+ while valid:
+ count += 1
+ print "Console Event:", self._event.kind
+ if self._event.kind == qmfengine.ConsoleEvent.AGENT_ADDED:
+ pass
+ elif self._event.kind == qmfengine.ConsoleEvent.AGENT_DELETED:
+ pass
+ elif self._event.kind == qmfengine.ConsoleEvent.NEW_PACKAGE:
+ pass
+ elif self._event.kind == qmfengine.ConsoleEvent.NEW_CLASS:
+ pass
+ elif self._event.kind == qmfengine.ConsoleEvent.OBJECT_UPDATE:
+ pass
+ elif self._event.kind == qmfengine.ConsoleEvent.EVENT_RECEIVED:
+ pass
+ elif self._event.kind == qmfengine.ConsoleEvent.AGENT_HEARTBEAT:
+ pass
+ elif self._event.kind == qmfengine.ConsoleEvent.METHOD_RESPONSE:
+ pass
+
+ self.impl.popEvent()
+ valid = self.impl.getEvent(self._event)
+ return count
+
+
+
+class Broker(ConnectionHandler):
+ # attr_reader :impl
+ def __init__(self, console, conn):
+ self._console = console
+ self._conn = conn
+ self._session = None
+ self._event = qmfengine.BrokerEvent()
+ self._xmtMessage = qmfengine.Message()
+ self.impl = qmfengine.BrokerProxy(self._console.impl)
+ self._console.impl.addConnection(self.impl, self)
+ self._conn.add_conn_handler(self)
+
+
+ def do_broker_events(self):
+ count = 0
+ valid = self.impl.getEvent(self._event)
+ while valid:
+ count += 1
+ print "Broker Event: ", self._event.kind
+ if self._event.kind == qmfengine.BrokerEvent.BROKER_INFO:
+ pass
+ elif self._event.kind == qmfengine.BrokerEvent.DECLARE_QUEUE:
+ self._conn.impl.declareQueue(self._session.handle, self._event.name)
+ elif self._event.kind == qmfengine.BrokerEvent.DELETE_QUEUE:
+ self._conn.impl.deleteQueue(self._session.handle, self._event.name)
+ elif self._event.kind == qmfengine.BrokerEvent.BIND:
+ self._conn.impl.bind(self._session.handle, self._event.exchange, self._event.name, self._event.bindingKey)
+ elif self._event.kind == qmfengine.BrokerEvent.UNBIND:
+ self._conn.impl.unbind(self._session.handle, self._event.exchange, self._event.name, self._event.bindingKey)
+ elif self._event.kind == qmfengine.BrokerEvent.SETUP_COMPLETE:
+ self.impl.startProtocol()
+
+ self.impl.popEvent()
+ valid = self.impl.getEvent(self._event)
+
+ return count
+
+
+ def do_broker_messages(self):
+ count = 0
+ valid = self.impl.getXmtMessage(self._xmtMessage)
+ while valid:
+ count += 1
+ self._conn.impl.sendMessage(self._session.handle, self._xmtMessage)
+ self.impl.popXmt()
+ valid = self.impl.getXmtMessage(self._xmtMessage)
+
+ return count
+
+
+ def do_events(self):
+ while True:
+ ccnt = self._console.do_console_events()
+ bcnt = do_broker_events()
+ mcnt = do_broker_messages()
+ if ccnt == 0 and bcnt == 0 and mcnt == 0:
+ break;
+
+
+ def conn_event_connected(self):
+ print "Console Connection Established..."
+ self._session = Session(self._conn, "qmfc-%s.%d" % (socket.gethostname(), os.getpid()), self)
+ self.impl.sessionOpened(self._session.handle)
+ self.do_events()
+
+
+ def conn_event_disconnected(self, error):
+ print "Console Connection Lost"
+ pass
+
+
+ def sess_event_session_closed(self, context, error):
+ print "Console Session Lost"
+ self.impl.sessionClosed()
+
+
+ def sess_event_recv(self, context, message):
+ self.impl.handleRcvMessage(message)
+ self.do_events()
+
+
+
+ ##==============================================================================
+ ## AGENT
+ ##==============================================================================
+
+
+
+class AgentHandler:
+ def get_query(self, context, query, userId): None
+ def method_call(self, context, name, object_id, args, userId): None
+
+
+
+class Agent(ConnectionHandler):
+ def __init__(self, handler, label=""):
+ if label == "":
+ self._agentLabel = "rb-%s.%d" % (socket.gethostname(), os.getpid())
+ else:
+ self._agentLabel = label
+ self._conn = None
+ self._handler = handler
+ self.impl = qmfengine.AgentEngine(self._agentLabel)
+ self._event = qmfengine.AgentEvent()
+ self._xmtMessage = qmfengine.Message()
+
+
+ def set_connection(self, conn):
+ self._conn = conn
+ self._conn.add_conn_handler(self)
+
+
+ def register_class(self, cls):
+ self.impl.registerClass(cls.impl)
+
+
+ def alloc_object_id(self, low = 0, high = 0):
+ return ObjectId(self.impl.allocObjectId(low, high))
+
+
+ def query_response(self, context, obj):
+ self.impl.queryResponse(context, obj.impl)
+
+
+ def query_complete(self, context):
+ self.impl.queryComplete(context)
+
+
+ def method_response(self, context, status, text, arguments):
+ self.impl.methodResponse(context, status, text, arguments.map)
+
+
+ def do_agent_events(self):
+ count = 0
+ valid = self.impl.getEvent(self._event)
+ while valid:
+ count += 1
+ if self._event.kind == qmfengine.AgentEvent.GET_QUERY:
+ self._handler.get_query(self._event.sequence,
+ Query(self._event.query),
+ self._event.authUserId)
+
+ elif self._event.kind == qmfengine.AgentEvent.START_SYNC:
+ pass
+ elif self._event.kind == qmfengine.AgentEvent.END_SYNC:
+ pass
+ elif self._event.kind == qmfengine.AgentEvent.METHOD_CALL:
+ args = Arguments(self._event.arguments)
+ self._handler.method_call(self._event.sequence, self._event.name,
+ ObjectId(self._event.objectId),
+ args, self._event.authUserId)
+
+ elif self._event.kind == qmfengine.AgentEvent.DECLARE_QUEUE:
+ self._conn.impl.declareQueue(self._session.handle, self._event.name)
+
+ elif self._event.kind == qmfengine.AgentEvent.DELETE_QUEUE:
+ self._conn.impl.deleteQueue(self._session.handle, self._event.name)
+
+ elif self._event.kind == qmfengine.AgentEvent.BIND:
+ self._conn.impl.bind(self._session.handle, self._event.exchange,
+ self._event.name, self._event.bindingKey)
+
+ elif self._event.kind == qmfengine.AgentEvent.UNBIND:
+ self._conn.impl.unbind(self._session.handle, self._event.exchange,
+ self._event.name, self._event.bindingKey)
+
+ elif self._event.kind == qmfengine.AgentEvent.SETUP_COMPLETE:
+ self.impl.startProtocol()
+
+ self.impl.popEvent()
+ valid = self.impl.getEvent(self._event)
+ return count
+
+
+ def do_agent_messages(self):
+ count = 0
+ valid = self.impl.getXmtMessage(self._xmtMessage)
+ while valid:
+ count += 1
+ self._conn.impl.sendMessage(self._session.handle, self._xmtMessage)
+ self.impl.popXmt()
+ valid = self.impl.getXmtMessage(self._xmtMessage)
+ return count
+
+
+ def do_events(self):
+ while True:
+ ecnt = self.do_agent_events()
+ mcnt = self.do_agent_messages()
+ if ecnt == 0 and mcnt == 0:
+ break
+
+
+ def conn_event_connected(self):
+ print "Agent Connection Established..."
+ self._session = Session(self._conn,
+ "qmfa-%s.%d" % (socket.gethostname(), os.getpid()),
+ self)
+ self.impl.newSession()
+ self.do_events()
+
+
+ def conn_event_disconnected(self, error):
+ print "Agent Connection Lost"
+ pass
+
+
+ def sess_event_session_closed(self, context, error):
+ print "Agent Session Lost"
+ pass
+
+
+ def sess_event_recv(self, context, message):
+ self.impl.handleRcvMessage(message)
+ self.do_events()
+
+
diff --git a/cpp/bindings/qmf/tests/python_agent.py b/cpp/bindings/qmf/tests/python_agent.py
new file mode 100644
index 0000000000..f6cb51cbf5
--- /dev/null
+++ b/cpp/bindings/qmf/tests/python_agent.py
@@ -0,0 +1,192 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+import qmf
+import sys
+import time
+
+
+class Model:
+ # attr_reader :parent_class, :child_class
+ def __init__(self):
+ self.parent_class = qmf.SchemaObjectClass("org.apache.qpid.qmf", "parent")
+ self.parent_class.add_property(qmf.SchemaProperty("name", qmf.TYPE_SSTR, {"index":True}))
+ self.parent_class.add_property(qmf.SchemaProperty("state", qmf.TYPE_SSTR))
+
+ self.parent_class.add_property(qmf.SchemaProperty("uint64val", qmf.TYPE_UINT64))
+ self.parent_class.add_property(qmf.SchemaProperty("uint32val", qmf.TYPE_UINT32))
+ self.parent_class.add_property(qmf.SchemaProperty("uint16val", qmf.TYPE_UINT16))
+ self.parent_class.add_property(qmf.SchemaProperty("uint8val", qmf.TYPE_UINT8))
+
+ self.parent_class.add_property(qmf.SchemaProperty("int64val", qmf.TYPE_INT64))
+ self.parent_class.add_property(qmf.SchemaProperty("int32val", qmf.TYPE_INT32))
+ self.parent_class.add_property(qmf.SchemaProperty("int16val", qmf.TYPE_INT16))
+ self.parent_class.add_property(qmf.SchemaProperty("int8val", qmf.TYPE_INT8))
+
+ self.parent_class.add_statistic(qmf.SchemaStatistic("queryCount", qmf.TYPE_UINT32, {"unit":"query", "desc":"Query count"}))
+
+ _method = qmf.SchemaMethod("echo", {"desc":"Check responsiveness of the agent object"})
+ _method.add_argument(qmf.SchemaArgument("sequence", qmf.TYPE_UINT32, {"dir":qmf.DIR_IN_OUT}))
+ self.parent_class.add_method(_method)
+
+ _method = qmf.SchemaMethod("set_numerics", {"desc":"Set the numeric values in the object"})
+ _method.add_argument(qmf.SchemaArgument("test", qmf.TYPE_SSTR, {"dir":qmf.DIR_IN}))
+ self.parent_class.add_method(_method)
+
+ _method = qmf.SchemaMethod("create_child", {"desc":"Create a new child object"})
+ _method.add_argument(qmf.SchemaArgument("child_name", qmf.TYPE_LSTR, {"dir":qmf.DIR_IN}))
+ _method.add_argument(qmf.SchemaArgument("child_ref", qmf.TYPE_REF, {"dir":qmf.DIR_OUT}))
+ self.parent_class.add_method(_method)
+
+ _method = qmf.SchemaMethod("probe_userid", {"desc":"Return the user-id for this method call"})
+ _method.add_argument(qmf.SchemaArgument("userid", qmf.TYPE_SSTR, {"dir":qmf.DIR_OUT}))
+ self.parent_class.add_method(_method)
+
+ self.child_class = qmf.SchemaObjectClass("org.apache.qpid.qmf", "child")
+ self.child_class.add_property(qmf.SchemaProperty("name", qmf.TYPE_SSTR, {"index":True}))
+
+
+ def register(self, agent):
+ agent.register_class(self.parent_class)
+ agent.register_class(self.child_class)
+
+
+
+class App(qmf.AgentHandler):
+ def get_query(self, context, query, userId):
+ # puts "Query: user=#{userId} context=#{context} class=#{query.class_name} object_num=#{query.object_id.object_num_low if query.object_id}"
+ self._parent.inc_attr("queryCount")
+ if query.class_name() == 'parent':
+ self._agent.query_response(context, self._parent)
+ elif query.object_id() == self._parent_oid:
+ self._agent.query_response(context, self._parent)
+ self._agent.query_complete(context)
+
+
+ def method_call(self, context, name, object_id, args, userId):
+ # puts "Method: user=#{userId} context=#{context} method=#{name} object_num=#{object_id.object_num_low if object_id} args=#{args}"
+ # oid = self._agent.alloc_object_id(2)
+ # args['child_ref'] = oid
+ # self._child = qmf.QmfObject(self._model.child_class)
+ # self._child.set_attr("name", args.by_key("child_name"))
+ # self._child.set_object_id(oid)
+ # self._agent.method_response(context, 0, "OK", args)
+ if name == "echo":
+ self._agent.method_response(context, 0, "OK", args)
+
+ elif name == "set_numerics":
+ _retCode = 0
+ _retText = "OK"
+
+ if args['test'] == "big":
+ self._parent.set_attr("uint64val", 0x9494949449494949)
+ self._parent.set_attr("uint32val", 0xa5a55a5a)
+ self._parent.set_attr("uint16val", 0xb66b)
+ self._parent.set_attr("uint8val", 0xc7)
+
+ self._parent.set_attr("int64val", 1000000000000000000)
+ self._parent.set_attr("int32val", 1000000000)
+ self._parent.set_attr("int16val", 10000)
+ self._parent.set_attr("int8val", 100)
+
+ elif args['test'] == "small":
+ self._parent.set_attr("uint64val", 4)
+ self._parent.set_attr("uint32val", 5)
+ self._parent.set_attr("uint16val", 6)
+ self._parent.set_attr("uint8val", 7)
+
+ self._parent.set_attr("int64val", 8)
+ self._parent.set_attr("int32val", 9)
+ self._parent.set_attr("int16val", 10)
+ self._parent.set_attr("int8val", 11)
+
+ elif args['test'] == "negative":
+ self._parent.set_attr("uint64val", 0)
+ self._parent.set_attr("uint32val", 0)
+ self._parent.set_attr("uint16val", 0)
+ self._parent.set_attr("uint8val", 0)
+
+ self._parent.set_attr("int64val", -10000000000)
+ self._parent.set_attr("int32val", -100000)
+ self._parent.set_attr("int16val", -1000)
+ self._parent.set_attr("int8val", -100)
+
+ else:
+ _retCode = 1
+ _retText = "Invalid argument value for test"
+
+ self._agent.method_response(context, _retCode, _retText, args)
+
+ elif name == "create_child":
+ _oid = self._agent.alloc_object_id(2)
+ args['child_ref'] = _oid
+ self._child = qmf.QmfObject(self._model.child_class)
+ self._child.set_attr("name", args["child_name"])
+ self._child.set_object_id(_oid)
+ self._agent.method_response(context, 0, "OK", args)
+
+ elif name == "probe_userid":
+ args['userid'] = userId
+ self._agent.method_response(context, 0, "OK", args)
+
+ else:
+ self._agent.method_response(context, 1, "Unimplemented Method: %s" % name, args)
+
+
+ def main(self):
+ self._settings = qmf.ConnectionSettings()
+ if len(sys.argv) > 1:
+ self._settings.set_attr("host", sys.argv[1])
+ if len(sys.argv) > 2:
+ self._settings.set_attr("port", int(sys.argv[2]))
+ self._connection = qmf.Connection(self._settings)
+ self._agent = qmf.Agent(self)
+
+ self._model = Model()
+ self._model.register(self._agent)
+
+ self._agent.set_connection(self._connection)
+
+ self._parent = qmf.QmfObject(self._model.parent_class)
+ self._parent.set_attr("name", "Parent One")
+ self._parent.set_attr("state", "OPERATIONAL")
+
+ self._parent.set_attr("uint64val", 0)
+ self._parent.set_attr("uint32val", 0)
+ self._parent.set_attr("uint16val", 0)
+ self._parent.set_attr("uint8val", 0)
+
+ self._parent.set_attr("int64val", 0)
+ self._parent.set_attr("int32val", 0)
+ self._parent.set_attr("int16val", 0)
+ self._parent.set_attr("int8val", 0)
+
+ self._parent_oid = self._agent.alloc_object_id(1)
+ self._parent.set_object_id(self._parent_oid)
+
+ while True: # there may be a better way, but
+ time.sleep(1000) # I'm a python noob...
+
+
+
+app = App()
+app.main()
+
diff --git a/cpp/bindings/qmf/tests/run_interop_tests b/cpp/bindings/qmf/tests/run_interop_tests
index f3f78185c7..d0e1662f3b 100755
--- a/cpp/bindings/qmf/tests/run_interop_tests
+++ b/cpp/bindings/qmf/tests/run_interop_tests
@@ -49,17 +49,44 @@ stop_ruby_agent() {
kill $AGENT_PID
}
+start_python_agent() {
+ PYTHONPATH="${MY_DIR}/../python:${API_DIR}/python:${API_DIR}/python/.libs" python ${MY_DIR}/python_agent.py localhost $BROKER_PORT &
+ PY_AGENT_PID=$!
+}
+
+stop_python_agent() {
+ kill $PY_AGENT_PID
+}
+
+TESTS_FAILED=0
+
if test -d ${PYTHON_DIR} ; then
start_broker
echo "Running qmf interop tests using broker on port $BROKER_PORT"
PYTHONPATH=${PYTHON_DIR}:${MY_DIR}
export PYTHONPATH
+
+ echo " Python Agent (external storage) vs. Pure-Python Console"
+ start_python_agent
+ echo " Python agent started at pid $PY_AGENT_PID"
+ ${PYTHON_DIR}/qpid-python-test -m python_console -b localhost:$BROKER_PORT $@
+ RETCODE=$?
+ stop_python_agent
+ if test x$RETCODE != x0; then
+ echo "FAIL qmf interop tests (Python Agent)";
+ TESTS_FAILED=1
+ fi
+
echo " Ruby Agent (external storage) vs. Pure-Python Console"
start_ruby_agent
echo " Ruby agent started at pid $AGENT_PID"
${PYTHON_DIR}/qpid-python-test -m python_console -b localhost:$BROKER_PORT $@
RETCODE=$?
stop_ruby_agent
+ if test x$RETCODE != x0; then
+ echo "FAIL qmf interop tests (Ruby Agent)";
+ TESTS_FAILED=1
+ fi
# Also against the Pure-Python console:
# Ruby agent (internal storage)
@@ -72,7 +99,8 @@ if test -d ${PYTHON_DIR} ; then
# C++ console
stop_broker
- if test x$RETCODE != x0; then
- echo "FAIL qmf interop tests"; exit 1;
+ if test x$TESTS_FAILED != x0; then
+ echo "TEST FAILED!"
+ exit 1
fi
fi
diff --git a/cpp/configure.ac b/cpp/configure.ac
index a4e45ad19b..7eb1e99159 100644
--- a/cpp/configure.ac
+++ b/cpp/configure.ac
@@ -515,6 +515,7 @@ AC_CONFIG_FILES([
examples/messaging/Makefile
bindings/qmf/Makefile
bindings/qmf/ruby/Makefile
+ bindings/qmf/python/Makefile
bindings/qmf/tests/Makefile
managementgen/Makefile
etc/Makefile
diff --git a/cpp/src/qmf/AgentEngine.h b/cpp/src/qmf/AgentEngine.h
index bbfbada80c..c88ef33657 100644
--- a/cpp/src/qmf/AgentEngine.h
+++ b/cpp/src/qmf/AgentEngine.h
@@ -182,7 +182,7 @@ namespace qmf {
*@return The objectId of the managed object.
*/
const ObjectId* addObject(Object& obj, uint64_t persistId);
- const ObjectId* addObject(Object& obj, uint32_t persistIdLo, uint32_t persistIdHi);
+ // const ObjectId* addObject(Object& obj, uint32_t persistIdLo, uint32_t persistIdHi);
/**
* Allocate an object-id for an object that will be managed by the application.
diff --git a/cpp/src/qmf/Value.h b/cpp/src/qmf/Value.h
index a45df14ea9..bb946d31d3 100644
--- a/cpp/src/qmf/Value.h
+++ b/cpp/src/qmf/Value.h
@@ -30,7 +30,7 @@ namespace qmf {
class Value {
public:
- Value();
+ // Value();
Value(Typecode t, Typecode arrayType = TYPE_UINT8);
Value(ValueImpl* impl);
~Value();