[Uludag-commits] r16303 - in branches/comar-dbus: comar comar/etc comar/etc/introspections comar/include comar/src tests tests/scripts

uludag-commits at pardus.org.tr uludag-commits at pardus.org.tr
12 Ara 2007 Çar 16:31:32 EET


Author: bahadir.kandemir
Date: Wed Dec 12 16:31:31 2007
New Revision: 16303

Added:
   branches/comar-dbus/comar/etc/model.xml
Removed:
   branches/comar-dbus/comar/etc/introspections/
   branches/comar-dbus/comar/include/xml.h
   branches/comar-dbus/comar/src/xml.c
Modified:
   branches/comar-dbus/comar/CMakeLists.txt
   branches/comar-dbus/comar/include/csl.h
   branches/comar-dbus/comar/include/model.h
   branches/comar-dbus/comar/include/utility.h
   branches/comar-dbus/comar/src/csl.c
   branches/comar-dbus/comar/src/dbus.c
   branches/comar-dbus/comar/src/main.c
   branches/comar-dbus/comar/src/model.c
   branches/comar-dbus/comar/src/utility.c
   branches/comar-dbus/tests/hav.py
   branches/comar-dbus/tests/scripts/System_Package_mysql.py
Log:
Moved all introspection code into model.xml. Comar will retrieve 
object path's introspection from model.xml when needed.

Ported model table code from Comar 1.*, now we're keeping interface, method and signal records.


Modified: branches/comar-dbus/comar/CMakeLists.txt
=================================================================
--- branches/comar-dbus/comar/CMakeLists.txt	(original)
+++ branches/comar-dbus/comar/CMakeLists.txt	Wed Dec 12 16:31:31 2007
@@ -23,5 +23,4 @@
                           src/log.c
                           src/process.c
                           src/model.c
-                          src/utility.c
-                          src/xml.c)
+                          src/utility.c)

Modified: branches/comar-dbus/comar/include/csl.h
=================================================================
--- branches/comar-dbus/comar/include/csl.h	(original)
+++ branches/comar-dbus/comar/include/csl.h	Wed Dec 12 16:31:31 2007
@@ -17,7 +17,6 @@
 int py_call_method(const char *app, const char *model, const char *method, PyObject *args, PyObject **result);
 PyObject *dbus_py_import(DBusMessage *msg);
 int dbus_py_export(DBusMessageIter *iter, PyObject *obj);
-PyObject *py_str_split(char *str, char delimiter);
 
 PyObject *dbus_py_get_list(DBusMessageIter *iter);
 PyObject *dbus_py_get_dict(DBusMessageIter *iter);

Modified: branches/comar-dbus/comar/include/model.h
=================================================================
--- branches/comar-dbus/comar/include/model.h	(original)
+++ branches/comar-dbus/comar/include/model.h	Wed Dec 12 16:31:31 2007
@@ -7,5 +7,12 @@
 ** option) any later version. Please read the COPYING file.
 */
 
-extern char *model_list;
+#include "iksemel.h"
+
+extern iks *model_xml;
+
+int model_lookup_interface(const char *iface);
+int model_lookup_method(const char *iface, const char *method);
+int model_lookup_signal(const char *iface, const char *signal);
+int model_get_iks(char *iface, iks **parent);
 int model_init();

Modified: branches/comar-dbus/comar/include/utility.h
=================================================================
--- branches/comar-dbus/comar/include/utility.h	(original)
+++ branches/comar-dbus/comar/include/utility.h	Wed Dec 12 16:31:31 2007
@@ -19,7 +19,4 @@
 int check_model_name(const char *model);
 int check_app_name(const char *app);
 char *get_script_path(const char *interface, const char *path);
-char *get_xml_path(const char *model);
 unsigned long time_diff(struct timeval *start, struct timeval *end);
-
-int str_in_list(const char *item, char delim, const char *list);

Modified: branches/comar-dbus/comar/src/csl.c
=================================================================
--- branches/comar-dbus/comar/src/csl.c	(original)
+++ branches/comar-dbus/comar/src/csl.c	Wed Dec 12 16:31:31 2007
@@ -72,7 +72,7 @@
         tuple = PyTuple_New(0);
     }
 
-    if (db_check_model(app, model)) {
+    if (db_check_model(app, model) && model_lookup_method(model, method) != -1) {
         ret = py_call_method(app, model, method, tuple, &result);
 
         if (ret == 0) {
@@ -84,7 +84,7 @@
         return NULL;
     }
     else {
-        PyErr_SetString(PyExc_Exception, "Invalid application or model.");
+        PyErr_SetString(PyExc_Exception, "Invalid application, model or method.");
         return NULL;
     }
 }
@@ -101,10 +101,19 @@
     path = dbus_message_get_path(my_proc.bus_msg);
     interface = dbus_message_get_interface(my_proc.bus_msg);
 
-    dbus_signal(path, interface, method, PyString_FromString(msg));
+    char *model = (char *) strsub(interface, strlen(cfg_bus_name) + 1, 0);
 
-    Py_INCREF(Py_None);
-    return Py_None;
+    if (model_lookup_signal(model, method) != -1) {
+        dbus_signal(path, interface, method, PyString_FromString(msg));
+        free(model);
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+    else {
+        free(model);
+        PyErr_SetString(PyExc_Exception, "Invalid application, model or method.");
+        return NULL;
+    }
 }
 
 static PyObject *
@@ -130,44 +139,6 @@
     { NULL, NULL, 0, NULL }
 };
 
-
-PyObject *
-py_str_split(char *str, char delimiter)
-{
-    PyObject *result = PyList_New(0);
-
-    if (str == NULL) {
-        return result;
-    }
-
-    char *t, *s;
-    t = strdup(str);
-    for (; t; t = s) {
-        s = strchr(t, '|');
-        if (s) {
-            *s = '\0';
-            ++s;
-        }
-        if (strlen(t) > 0) {
-            PyList_Append(result, PyString_FromString(t));
-        }
-    }
-    free(str);
-    return result;
-}
-
-int
-py_in_tuple(PyObject *tuple, PyObject *item)
-{
-    int i;
-    for (i = 0; i < PyTuple_Size(tuple); i++) {
-        if (strcmp(PyString_AsString(item), PyString_AsString(PyTuple_GetItem(tuple, i))) == 0) {
-            return 1;
-        }
-    }
-    return 0;
-}
-
 int
 py_compile(const char *script_path)
 {

Modified: branches/comar-dbus/comar/src/dbus.c
=================================================================
--- branches/comar-dbus/comar/src/dbus.c	(original)
+++ branches/comar-dbus/comar/src/dbus.c	Wed Dec 12 16:31:31 2007
@@ -20,7 +20,6 @@
 #include "model.h"
 #include "process.h"
 #include "utility.h"
-#include "xml.h"
 
 void
 dbus_send(DBusMessage *reply)
@@ -126,33 +125,69 @@
 static void
 dbus_introspection_methods(const char *path)
 {
-    char *intros, *app;
-
     if (strcmp(path, "/") == 0) {
-        xml_export_nodes("system|package", &intros);
-        dbus_reply_str(intros);
-        free(intros);
+        iks *xml = iks_new("node");
+
+        // package node contains applications and models
+        iks_insert_attrib(iks_insert(xml, "node"), "name", "package");
+
+        // system node contains Comar methods (register, remove, ...)
+        iks_insert_attrib(iks_insert(xml, "node"), "name", "system");
+
+        dbus_reply_str(iks_string(NULL, xml));
+        iks_delete(xml);
     }
     else if (strcmp(path, "/system") == 0) {
-        xml_export_system(&intros);
-        dbus_reply_str(intros);
-        free(intros);
+        iks *xml = iks_new("node");
+        model_get_iks("Comar", &xml);
+        dbus_reply_str(iks_string(NULL, xml));
+        iks_delete(xml);
     }
     else if (strcmp(path, "/package") == 0) {
-        xml_export_apps(&intros);
-        dbus_reply_str(intros);
-        free(intros);
+        char *apps;
+        db_get_apps(&apps);
+        if (apps == NULL) {
+            dbus_reply_str("<node/>");;
+        }
+        else {
+            iks *xml = iks_new("node");
+            char *pch = strtok(apps, "|");
+            while (pch != NULL) {
+                if (strlen(pch) > 0) {
+                    iks_insert_attrib(iks_insert(xml, "node"), "name", pch);
+                }
+                pch = strtok(NULL, "|");
+            }
+            dbus_reply_str(iks_string(NULL, xml));
+            iks_delete(xml);
+            free(apps);
+        }
     }
     else if (strncmp(path, "/package/", strlen("/package/")) == 0) {
-        app = (char *) strsub(path, strlen("/package/"), 0);
+        char *app = (char *) strsub(path, strlen("/package/"), 0);
         if (!db_check_app(app)) {
             log_error("No such application: '%s'\n", app);
             dbus_reply_error("No such application");
         }
         else {
-            xml_export_interfaces(app, &intros);
-            dbus_reply_str(intros);
-            free(intros);
+            char *models;
+            db_get_models(app, &models);
+            if (models == NULL) {
+                dbus_reply_str("<node/>");;
+            }
+            else {
+                iks *xml = iks_new("node");
+                char *pch = strtok(models, "|");
+                while (pch != NULL) {
+                    if (strlen(pch) > 0) {
+                        model_get_iks(pch, &xml);
+                    }
+                    pch = strtok(NULL, "|");
+                }
+                dbus_reply_str(iks_string(NULL, xml));
+                iks_delete(xml);
+                free(models);
+            }
         }
         free(app);
     }
@@ -165,30 +200,55 @@
 static void
 dbus_comar_methods(const char *method)
 {
-    PyObject *args, *result, *list;
+    PyObject *args, *result;
     char *app, *model, *script, *apps, *models, *code;
     int i;
 
     if (strcmp(method, "listApplications") == 0) {
         db_get_apps(&apps);
-        result = py_str_split(apps, '|');
+        result = PyList_New(0);
+        if (apps != NULL) {
+            char *pch = strtok(apps, "|");
+            while (pch != NULL) {
+                if (strlen(pch) > 0) {
+                    PyList_Append(result, PyString_FromString(pch));
+                }
+                pch = strtok(NULL, "|");
+            }
+            free(apps);
+        }
         dbus_reply_object(result);
     }
     else if (strcmp(method, "listModels") == 0) {
-        result = py_str_split(model_list, '|');
+        result = PyList_New(0);
+        iks *obj;
+        for (obj = iks_first_tag(model_xml); obj; obj = iks_next_tag(obj)) {
+            if (iks_strcmp(iks_find_attrib(obj, "name"), "Comar") == 0) {
+                continue;
+            }
+            PyList_Append(result, PyString_FromString(iks_find_attrib(obj, "name")));
+        }
         dbus_reply_object(result);
     }
     else if (strcmp(method, "listApplicationModels") == 0) {
         args = dbus_py_import(my_proc.bus_msg);
         app = PyString_AsString(PyList_GetItem(args, 0));
         db_get_models(app, &models);
-        if (models == NULL) {
-            log_error("No such application: '%s'\n", app);
-            dbus_reply_error("No such application");
+        if (models != NULL) {
+            result = PyList_New(0);
+            char *pch = strtok(models, "|");
+            while (pch != NULL) {
+                if (strlen(pch) > 0) {
+                    PyList_Append(result, PyString_FromString(pch));
+                }
+                pch = strtok(NULL, "|");
+            }
+            dbus_reply_object(result);
+            free(models);
         }
         else {
-            result = py_str_split(models, '|');
-            dbus_reply_object(result);
+            log_error("No such application: '%s'\n", app);
+            dbus_reply_error("No such application");
         }
     }
     else if (strcmp(method, "register") == 0) {
@@ -197,7 +257,7 @@
         model = PyString_AsString(PyList_GetItem(args, 1));
         script = PyString_AsString(PyList_GetItem(args, 2));
 
-        if (!str_in_list(model, '|', model_list) != 0) {
+        if (model_lookup_interface(model) == -1) {
             log_error("No such model: '%s'\n", model);
             dbus_reply_error("No such model.");
         }
@@ -226,11 +286,15 @@
         else {
             db_remove_app(app);
 
-            list = py_str_split(models, '|');
-            for (i = 0; i < PyList_Size(list); i++) {
-                script = get_script_path(app, PyString_AsString(PyList_GetItem(list, i)));
-                unlink(script);
+            char *pch = strtok(models, "|");
+            while (pch != NULL) {
+                if (strlen(pch) > 0) {
+                    script = get_script_path(app, pch);
+                    unlink(script);
+                }
+                pch = strtok(NULL, "|");
             }
+
             dbus_reply_object(Py_True);
         }
     }
@@ -251,12 +315,12 @@
     char *app = (char *) strsub(path, strlen("/package/"), 0);
     char *model = (char *) strsub(interface, strlen(cfg_bus_name) + 1, 0);
 
-    if (db_check_model(app, model)) {
+    if (db_check_model(app, model) && model_lookup_method(model, method) != -1) {
         args = PyList_AsTuple(dbus_py_import(my_proc.bus_msg));
         ret = py_call_method(app, model, method, args, &result);
 
         if (ret == 1) {
-            log_error("Unable to find code for '%s/%s'\n", model, app);
+            log_error("Unable to find: %s (%s)\n", model, app);
             dbus_reply_error("Internal error, unable to find script.");
         }
         else if (ret == 2) {
@@ -267,8 +331,8 @@
         }
     }
     else {
-        log_error("Invalid application or model '%s/%s'\n", model, app);
-        dbus_reply_error("Invalid application or model");
+        log_error("Invalid application, model or method: %s.%s (%s)\n", model, method, app);
+        dbus_reply_error("Invalid application, model or method.");
     }
     free(app);
     free(model);

Modified: branches/comar-dbus/comar/src/main.c
=================================================================
--- branches/comar-dbus/comar/src/main.c	(original)
+++ branches/comar-dbus/comar/src/main.c	Wed Dec 12 16:31:31 2007
@@ -43,7 +43,7 @@
 
     // Load models
     if (model_init() != 0) {
-        puts(_("Unable to load models."));
+        puts(_("Unable to load model.xml."));
         exit(1);
     }
 

Modified: branches/comar-dbus/comar/src/model.c
=================================================================
Suppressed!
	Too long (more than 250 lines) diff output suppressed...
Modified: branches/comar-dbus/comar/src/utility.c
=================================================================
--- branches/comar-dbus/comar/src/utility.c	(original)
+++ branches/comar-dbus/comar/src/utility.c	Wed Dec 12 16:31:31 2007
@@ -157,20 +157,6 @@
 }
 
 char *
-get_xml_path(const char *model)
-{
-    char *realpath;
-    int size;
-
-    size = strlen(cfg_config_dir) + 1 + strlen("introspections") + 1 + strlen(model) + 5;
-    realpath = malloc(size);
-
-    // Generate script path
-    snprintf(realpath, size, "%s/introspections/%s.xml\0", cfg_config_dir, model);
-    return realpath;
-}
-
-char *
 get_script_path(const char *app, const char *model)
 {
     char *realpath, *model_escaped, *t, *t2;
@@ -196,24 +182,3 @@
     msec -= (start->tv_sec * 1000) + (start->tv_usec / 1000);
     return msec;
 }
-
-int
-str_in_list(const char *item, char delim, const char *list)
-{
-    char *t, *s;
-
-    t = strdup(list);
-    if (!t) return -1;
-    for (; t; t = s) {
-        s = strchr(t, delim);
-        if (s) {
-            *s = '\0';
-            ++s;
-        }
-        if (strcmp(t, item) == 0) {
-            return 1;
-        }
-    }
-
-    return 0;
-}

Modified: branches/comar-dbus/tests/hav.py
=================================================================
--- branches/comar-dbus/tests/hav.py	(original)
+++ branches/comar-dbus/tests/hav.py	Wed Dec 12 16:31:31 2007
@@ -14,6 +14,7 @@
   %(name)s call <app> <model> <method> [args]
   %(name)s list [app]
   %(name)s listen
+  %(name)s models
   %(name)s register <app> <model> <script>
   %(name)s remove <app>
 ''' % {'name': sys.argv[0]}
@@ -97,6 +98,9 @@
                 return 1
             if iface.remove(app):
                 print "Removing %s" % app
+        elif cmd == "models":
+            for model in iface.listModels():
+                print model
         else:
             printUsage()
             return 1

Modified: branches/comar-dbus/tests/scripts/System_Package_mysql.py
=================================================================
--- branches/comar-dbus/tests/scripts/System_Package_mysql.py	(original)
+++ branches/comar-dbus/tests/scripts/System_Package_mysql.py	Wed Dec 12 16:31:31 2007
@@ -2,7 +2,9 @@
 # -*- coding: utf-8 -*-
 
 def postInstall(fromVersion, fromRelease, toVersion, toRelease):
+    notify("Installed", script())
     return True
 
 def preRemove():
+    notify("Removed", script())
     return True


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi