[Uludag-commits] r16235 - in branches/comar-dbus: include src tests
uludag-commits at pardus.org.tr
uludag-commits at pardus.org.tr
4 Ara 2007 Sal 21:47:22 EET
Author: bahadir.kandemir
Date: Tue Dec 4 21:47:22 2007
New Revision: 16235
Added:
branches/comar-dbus/tests/sample-async-cli.py
Modified:
branches/comar-dbus/include/csl.h
branches/comar-dbus/src/csl.c
branches/comar-dbus/src/dbus.c
branches/comar-dbus/tests/sample-cli.py
Log:
Removed support for keyword and optional arguments. This breaks
COMAR 1.* compatibility, but is required to serve a meaningfull
introspection.
It's time to work on introspection code...
Modified: branches/comar-dbus/include/csl.h
=================================================================
--- branches/comar-dbus/include/csl.h (original)
+++ branches/comar-dbus/include/csl.h Tue Dec 4 21:47:22 2007
@@ -13,4 +13,3 @@
PyObject *py_call_method(const char *model, const char *app, const char *method, PyObject *args);
PyObject *dbus_py_import(DBusMessage *msg);
void dbus_py_export(DBusMessageIter *iter, PyObject *obj);
-int py_check_args(PyObject *tuple);
Modified: branches/comar-dbus/src/csl.c
=================================================================
--- branches/comar-dbus/src/csl.c (original)
+++ branches/comar-dbus/src/csl.c Tue Dec 4 21:47:22 2007
@@ -27,30 +27,6 @@
return 0;
}
-int
-py_check_args(PyObject *tuple)
-{
- PyObject *pItem, *pKey;
- int i;
-
- if (!PyTuple_Check(tuple)) {
- return 0;
- }
-
- for (i == 0; i < PyTuple_Size(tuple); i++) {
- pItem = PyTuple_GetItem(tuple, i);
- if (!PyTuple_Check(pItem) || PyTuple_Size(pItem) != 2) {
- return 0;
- }
- pKey = PyTuple_GetItem(pItem, 0);
- if (!PyString_Check(pKey)) {
- return 0;
- }
- }
-
- return 1;
-}
-
//! Call model's method with given arguments
PyObject *
py_call_method(const char *model, const char *path, const char *method, PyObject *args)
@@ -102,23 +78,9 @@
return NULL;
}
- pFuncCode = PyObject_GetAttrString(pFunc, "func_code");
- arg_count = PyInt_AsLong(PyObject_GetAttrString(pFuncCode, "co_argcount"));
- argNames = PyObject_GetAttrString(pFuncCode, "co_varnames");
- argNames = PyTuple_GetSlice(argNames, 0, arg_count);
-
- pArgs = PyTuple_New(0);
+ pArgs = PyList_AsTuple(args);
pkArgs = PyDict_New();
- for (i = 0; i < PyTuple_Size(args); i++) {
- pKey = PyTuple_GetItem(PyTuple_GetItem(args, i), 0);
- pValue = PyTuple_GetItem(PyTuple_GetItem(args, i), 1);
- if (!py_in_tuple(argNames, pKey)) {
- continue;
- }
- PyDict_SetItem(pkArgs, pKey, pValue);
- }
-
pReturn = PyObject_Call(pFunc, pArgs, pkArgs);
if (!pReturn) {
Modified: branches/comar-dbus/src/dbus.c
=================================================================
--- branches/comar-dbus/src/dbus.c (original)
+++ branches/comar-dbus/src/dbus.c Tue Dec 4 21:47:22 2007
@@ -87,32 +87,26 @@
Py_Initialize();
obj = dbus_py_import(my_proc.bus_msg);
- obj = PyList_GetItem(obj, 0);
- if (!py_check_args(obj)) {
- log_error("%s.%s() argument format is not valid.\n", interface, method);
- if (!no_reply) {
- reply = dbus_message_new_error(my_proc.bus_msg, DBUS_ERROR_FAILED, "Argument format not valid");
- }
+ gettimeofday(&time_start, NULL);
+ ret = py_call_method(interface, path, method, obj);
+ gettimeofday(&time_end, NULL);
+ msec = time_diff(&time_start, &time_end);
+
+ if (msec / 1000 > 60) {
+ log_info("Execution of %s.%s (%s) took %.3f seconds\n", interface, method, path, (float) msec / 1000);
}
else {
- log_debug(LOG_CALL, "Executing %s.%s (%s)\n", interface, method, path);
-
- gettimeofday(&time_start, NULL);
- ret = py_call_method(interface, path, method, obj);
- gettimeofday(&time_end, NULL);
- msec = time_diff(&time_start, &time_end);
-
- log_debug(LOG_PERF, "Execution took %.3f seconds\n", (float) msec / 1000);
+ log_debug(LOG_PERF, "Execution of %s.%s (%s) took %.3f seconds\n", interface, method, path, (float) msec / 1000);
+ }
- if (ret == NULL) {
- reply = log_exception(my_proc.bus_msg, my_proc.bus_conn);
- }
- else if (!no_reply) {
- reply = dbus_message_new_method_return(my_proc.bus_msg);
- dbus_message_iter_init_append(reply, &iter);
- dbus_py_export(&iter, ret);
- }
+ if (ret == NULL) {
+ reply = log_exception(my_proc.bus_msg, my_proc.bus_conn);
+ }
+ else if (!no_reply) {
+ reply = dbus_message_new_method_return(my_proc.bus_msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_py_export(&iter, ret);
}
Py_Finalize();
@@ -166,8 +160,6 @@
unique_name = dbus_bus_get_unique_name(conn);
log_info("Listening on %s (%s)...\n", cfg_bus_name, unique_name);
- const char *introspection = load_file("/home/bahadir/repos/works/comar-dbus/introspection.xml", NULL);
-
while (1) {
dbus_connection_read_write(conn, 0);
msg = dbus_connection_pop_message(conn);
Modified: branches/comar-dbus/tests/sample-cli.py
=================================================================
--- branches/comar-dbus/tests/sample-cli.py (original)
+++ branches/comar-dbus/tests/sample-cli.py Tue Dec 4 21:47:22 2007
@@ -5,9 +5,16 @@
def main():
bus = dbus.SystemBus()
object = bus.get_object("tr.org.pardus.comar", "/package/mysql", introspect=False)
+ iface = dbus.Interface(object, "System.Package")
- args = {"a": 1, "b": 2.0, "c": "3"}
- print object.postInstall(tuple(args.items()), dbus_interface="System.Package")
+ def test(*args):
+ try:
+ print iface.postInstall(*args)
+ except Exception, e:
+ print e
+
+ test(1, [1, 2, 3])
+ test(1, [1, 2, 3], 1)
if __name__ == '__main__':
Uludag-commits mesaj listesiyle ilgili
daha fazla bilgi