[Uludag-commits] r16299 - in branches/comar-dbus/comar: . etc/introspections include src
uludag-commits at pardus.org.tr
uludag-commits at pardus.org.tr
11 Ara 2007 Sal 23:59:49 EET
Author: bahadir.kandemir
Date: Tue Dec 11 23:59:49 2007
New Revision: 16299
Added:
branches/comar-dbus/comar/etc/introspections/Boot.Loader.xml
- copied unchanged from r16294, branches/comar-dbus/comar/etc/introspections/Boot_Loader.xml
branches/comar-dbus/comar/etc/introspections/System.Package.xml
- copied, changed from r16293, branches/comar-dbus/comar/etc/introspections/System_Package.xml
branches/comar-dbus/comar/include/model.h
branches/comar-dbus/comar/src/model.c
Removed:
branches/comar-dbus/comar/etc/introspections/Boot_Loader.xml
branches/comar-dbus/comar/etc/introspections/System_Package.xml
Modified:
branches/comar-dbus/comar/CMakeLists.txt
branches/comar-dbus/comar/include/csl.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/utility.c
branches/comar-dbus/comar/src/xml.c
Log:
* Comar will load models on start up.
* `hav models` will return a list of available models.
* Fixed a bug in strsub()
* Moved Py_Init calls into forked function.
Modified: branches/comar-dbus/comar/CMakeLists.txt
=================================================================
--- branches/comar-dbus/comar/CMakeLists.txt (original)
+++ branches/comar-dbus/comar/CMakeLists.txt Tue Dec 11 23:59:49 2007
@@ -22,5 +22,6 @@
src/iksemel.c
src/log.c
src/process.c
+ src/model.c
src/utility.c
src/xml.c)
Copied: branches/comar-dbus/comar/etc/introspections/System.Package.xml (from r16293, branches/comar-dbus/comar/etc/introspections/System_Package.xml)
=================================================================
--- branches/comar-dbus/comar/etc/introspections/System_Package.xml (original)
+++ branches/comar-dbus/comar/etc/introspections/System.Package.xml Tue Dec 11 23:59:49 2007
@@ -7,4 +7,10 @@
</method>
<method name="preRemove">
</method>
+ <signal name="Installed">
+ <arg name="package" type="s"/>
+ </signal>
+ <signal name="Removed">
+ <arg name="package" type="s"/>
+ </signal>
</interface>
Modified: branches/comar-dbus/comar/include/csl.h
=================================================================
--- branches/comar-dbus/comar/include/csl.h (original)
+++ branches/comar-dbus/comar/include/csl.h Tue Dec 11 23:59:49 2007
@@ -10,6 +10,9 @@
#include <dbus/dbus.h>
#include <Python.h>
+void csl_init();
+void csl_end();
+
int py_compile(const char *script_path);
int py_call_method(const char *app, const char *model, const char *method, PyObject *args, PyObject **result);
PyObject *dbus_py_import(DBusMessage *msg);
Modified: branches/comar-dbus/comar/include/utility.h
=================================================================
--- branches/comar-dbus/comar/include/utility.h (original)
+++ branches/comar-dbus/comar/include/utility.h Tue Dec 11 23:59:49 2007
@@ -21,3 +21,5 @@
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 Tue Dec 11 23:59:49 2007
@@ -18,6 +18,18 @@
#include "process.h"
#include "utility.h"
+void
+csl_init()
+{
+ Py_Initialize();
+}
+
+void
+csl_end()
+{
+ Py_Finalize();
+}
+
static PyObject *
c_script(PyObject *self, PyObject *args)
{
@@ -123,6 +135,11 @@
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) {
@@ -131,7 +148,9 @@
*s = '\0';
++s;
}
- PyList_Append(result, PyString_FromString(t));
+ if (strlen(t) > 0) {
+ PyList_Append(result, PyString_FromString(t));
+ }
}
free(str);
return result;
Modified: branches/comar-dbus/comar/src/dbus.c
=================================================================
--- branches/comar-dbus/comar/src/dbus.c (original)
+++ branches/comar-dbus/comar/src/dbus.c Tue Dec 11 23:59:49 2007
@@ -17,6 +17,7 @@
#include "csl.h"
#include "iksemel.h"
#include "log.h"
+#include "model.h"
#include "process.h"
#include "utility.h"
#include "xml.h"
@@ -170,20 +171,14 @@
if (strcmp(method, "listApplications") == 0) {
db_get_apps(&apps);
- Py_Initialize();
result = py_str_split(apps, '|');
dbus_reply_object(result);
- Py_Finalize();
}
else if (strcmp(method, "listModels") == 0) {
- // TODO: List models
- Py_Initialize();
- result = py_str_split("", '|');
+ result = py_str_split(model_list, '|');
dbus_reply_object(result);
- Py_Finalize();
}
else if (strcmp(method, "listApplicationModels") == 0) {
- Py_Initialize();
args = dbus_py_import(my_proc.bus_msg);
app = PyString_AsString(PyList_GetItem(args, 0));
db_get_models(app, &models);
@@ -195,16 +190,14 @@
result = py_str_split(models, '|');
dbus_reply_object(result);
}
- Py_Finalize();
}
else if (strcmp(method, "register") == 0) {
- Py_Initialize();
args = dbus_py_import(my_proc.bus_msg);
app = PyString_AsString(PyList_GetItem(args, 0));
model = PyString_AsString(PyList_GetItem(args, 1));
script = PyString_AsString(PyList_GetItem(args, 2));
- if (!check_file(get_xml_path(model))) {
+ if (!str_in_list(model, '|', model_list) != 0) {
log_error("No such model: '%s'\n", model);
dbus_reply_error("No such model.");
}
@@ -220,10 +213,8 @@
dbus_reply_object(Py_True);
}
}
- Py_Finalize();
}
else if (strcmp(method, "remove") == 0) {
- Py_Initialize();
args = dbus_py_import(my_proc.bus_msg);
app = PyString_AsString(PyList_GetItem(args, 0));
db_get_models(app, &models);
@@ -242,7 +233,6 @@
}
dbus_reply_object(Py_True);
}
- Py_Finalize();
}
else {
log_error("Unknown method: '%s'\n", method);
@@ -262,8 +252,6 @@
char *model = (char *) strsub(interface, strlen(cfg_bus_name) + 1, 0);
if (db_check_model(app, model)) {
- Py_Initialize();
-
args = PyList_AsTuple(dbus_py_import(my_proc.bus_msg));
ret = py_call_method(app, model, method, args, &result);
@@ -277,8 +265,6 @@
else {
dbus_reply_object(result);
}
-
- Py_Finalize();
}
else {
log_error("Invalid application or model '%s/%s'\n", model, app);
@@ -302,9 +288,14 @@
gettimeofday(&time_start, NULL);
+ csl_init();
+
if (strcmp(interface, "org.freedesktop.DBus.Introspectable") == 0) {
dbus_introspection_methods(path);
}
+ else if (strcmp(interface, "org.freedesktop.DBus.Peer") == 0) {
+ // dbus_peer_methods(path);
+ }
else if (strncmp(interface, cfg_bus_name, strlen(cfg_bus_name)) == 0) {
if (strcmp(path, "/system") == 0 && strcmp(interface, cfg_bus_name) == 0) {
dbus_comar_methods(method);
@@ -329,6 +320,8 @@
else {
log_debug(LOG_PERF, "Execution of %s.%s (%s) took %.3f seconds\n", interface, method, path, (float) msec / 1000);
}
+
+ csl_end();
}
void
Modified: branches/comar-dbus/comar/src/main.c
=================================================================
--- branches/comar-dbus/comar/src/main.c (original)
+++ branches/comar-dbus/comar/src/main.c Tue Dec 11 23:59:49 2007
@@ -16,6 +16,7 @@
#include "dbus.h"
#include "i18n.h"
#include "log.h"
+#include "model.h"
#include "process.h"
int
@@ -40,6 +41,12 @@
exit(1);
}
+ // Load models
+ if (model_init() != 0) {
+ puts(_("Unable to load models."));
+ exit(1);
+ }
+
// Initialize DB
if (db_init() != 0) {
puts(_("Database is corrupt."));
Modified: branches/comar-dbus/comar/src/utility.c
=================================================================
--- branches/comar-dbus/comar/src/utility.c (original)
+++ branches/comar-dbus/comar/src/utility.c Tue Dec 11 23:59:49 2007
@@ -26,8 +26,8 @@
if (start < 0) {
start = strlen(str) + start;
}
- else if (start > strlen(str)) {
- end = strlen(str);
+ if (start > strlen(str)) {
+ start = 0;
}
if (end == 0) {
end = strlen(str);
@@ -35,7 +35,7 @@
else if (end < 0) {
end = strlen(str) + end;
}
- else if (end > strlen(str)) {
+ if (end > strlen(str)) {
end = strlen(str);
}
@@ -159,17 +159,14 @@
char *
get_xml_path(const char *model)
{
- char *realpath, *model_escaped, *t, *t2;
+ char *realpath;
int size;
size = strlen(cfg_config_dir) + 1 + strlen("introspections") + 1 + strlen(model) + 5;
realpath = malloc(size);
- model_escaped = (char *) strrep(model, '.', '_');
-
// Generate script path
- snprintf(realpath, size, "%s/introspections/%s.xml\0", cfg_config_dir, model_escaped);
- free(model_escaped);
+ snprintf(realpath, size, "%s/introspections/%s.xml\0", cfg_config_dir, model);
return realpath;
}
@@ -199,3 +196,24 @@
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/comar/src/xml.c
=================================================================
--- branches/comar-dbus/comar/src/xml.c (original)
+++ branches/comar-dbus/comar/src/xml.c Tue Dec 11 23:59:49 2007
@@ -48,8 +48,8 @@
xml_export_interfaces(char *app, char **intros)
{
int size;
- char *models;
- char *model_xml;
+ char *models, *model_xml, *xml_path;
+
db_get_models(app, &models);
size = strlen("<node></node>") + 1;
@@ -65,7 +65,9 @@
++s;
}
- model_xml = (char*) load_file(get_xml_path(t), NULL);
+ xml_path = get_xml_path(t);
+ model_xml = (char*) load_file(xml_path, NULL);
+ free(xml_path);
if (model_xml == NULL) {
log_error("Missing introspection data for '%s'\n", t);
@@ -88,13 +90,15 @@
xml_export_system(char **intros)
{
int size;
- char *model_xml;
+ char *model_xml, *xml_path;
size = strlen("<node></node>") + 1;
*intros = malloc(size);
snprintf(*intros, 7, "<node>\0");
- model_xml = (char*) load_file(get_xml_path("Comar"), NULL);
+ xml_path = get_xml_path("Comar");
+ model_xml = (char*) load_file(xml_path, NULL);
+ free(xml_path);
if (model_xml == NULL) {
log_error("Missing introspection data for 'Comar'\n");
Uludag-commits mesaj listesiyle ilgili
daha fazla bilgi