[Uludag-commits] r16294 - in branches/comar-dbus: comar/etc/introspections comar/include comar/src tests tests/data tests/scripts
uludag-commits at pardus.org.tr
uludag-commits at pardus.org.tr
11 Ara 2007 Sal 17:06:01 EET
Author: bahadir.kandemir
Date: Tue Dec 11 17:05:36 2007
New Revision: 16294
Added:
branches/comar-dbus/comar/etc/introspections/Comar.xml
branches/comar-dbus/tests/README
branches/comar-dbus/tests/register.py (contents, props changed)
branches/comar-dbus/tests/scripts/
branches/comar-dbus/tests/scripts/Boot_Loader_grub.py
branches/comar-dbus/tests/scripts/System_Package_mysql.py
branches/comar-dbus/tests/test.py
Removed:
branches/comar-dbus/tests/data/
branches/comar-dbus/tests/sample-async-cli.py
branches/comar-dbus/tests/sample-cli.py
branches/comar-dbus/tests/sample-gui.py
Modified:
branches/comar-dbus/comar/etc/introspections/Boot_Loader.xml
branches/comar-dbus/comar/include/csl.h
branches/comar-dbus/comar/include/dbus.h
branches/comar-dbus/comar/include/utility.h
branches/comar-dbus/comar/include/xml.h
branches/comar-dbus/comar/src/csl.c
branches/comar-dbus/comar/src/data.c
branches/comar-dbus/comar/src/dbus.c
branches/comar-dbus/comar/src/utility.c
branches/comar-dbus/comar/src/xml.c
branches/comar-dbus/tests/run.sh
Log:
Yet another -but hopefully last- long commit.
CSL
===
* call(app, model, method, (args, ...)) method for internal model calls.
* notify(signal, message) method for emitting DBus signals.
* script() method for getting application name within script file.
* fail(message) method for raising DBus exceptions
Utilities
=========
* str_*shift methods replaced with strsub(str, start, end) method
DBus
====
* .register(app, model, script_path) method for registering COMAR scripts.
* .remove(app) method for removing application (and it's scripts) from database
* .listApplications() method for listing registered applications
* .listApplicationModels(app) method for listing application's registered models
Modified: branches/comar-dbus/comar/etc/introspections/Boot_Loader.xml
=================================================================
--- branches/comar-dbus/comar/etc/introspections/Boot_Loader.xml (original)
+++ branches/comar-dbus/comar/etc/introspections/Boot_Loader.xml Tue Dec 11 17:05:36 2007
@@ -37,4 +37,7 @@
<method name="removeUnused">
<arg name="version" type="s" direction="in"/>
</method>
+ <signal name="Changed">
+ <arg name="changed_item" 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 17:05:36 2007
@@ -10,6 +10,13 @@
#include <dbus/dbus.h>
#include <Python.h>
+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);
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);
+PyObject *dbus_py_get_item(DBusMessageIter* iter);
+char *dbus_py_get_object_signature(PyObject *obj);
Modified: branches/comar-dbus/comar/include/dbus.h
=================================================================
--- branches/comar-dbus/comar/include/dbus.h (original)
+++ branches/comar-dbus/comar/include/dbus.h Tue Dec 11 17:05:36 2007
@@ -8,6 +8,10 @@
*/
#include <dbus/dbus.h>
+#include <Python.h>
+void dbus_send(DBusMessage *reply);
+void dbus_signal(char *path, char *interface, char *name, PyObject *obj);
void dbus_method_call(DBusMessage* msg, DBusConnection* conn);
void dbus_listen();
+void dbus_app_methods(const char *interface, const char *path, const char *method);
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 17:05:36 2007
@@ -9,12 +9,15 @@
#include <sys/time.h>
+char *strsub(char *str, int start, int end);
+char *strrep(char *str, char old, char new);
+
int check_file(const char *fname);
unsigned char *load_file(const char *fname, int *sizeptr);
+int save_file(const char *fname, const char *buffer, size_t size);
+
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);
-char *str_replace(const char *str, const char old, const char new);
-char *str_lshift(const char *str, int num);
Modified: branches/comar-dbus/comar/include/xml.h
=================================================================
--- branches/comar-dbus/comar/include/xml.h (original)
+++ branches/comar-dbus/comar/include/xml.h Tue Dec 11 17:05:36 2007
@@ -8,7 +8,6 @@
*/
int xml_export_nodes(char *nodes, char **bufferp);
-
int xml_export_apps(char **bufferp);
-
int xml_export_interfaces(char *app, char **intros);
+int xml_export_system(char **intros);
Modified: branches/comar-dbus/comar/src/csl.c
=================================================================
Suppressed!
Too long (more than 250 lines) diff output suppressed...
Modified: branches/comar-dbus/comar/src/data.c
=================================================================
--- branches/comar-dbus/comar/src/data.c (original)
+++ branches/comar-dbus/comar/src/data.c Tue Dec 11 17:05:36 2007
@@ -44,10 +44,10 @@
// FIXME: check perms and owner
}
- size = strlen(cfg_data_dir) + 11;
+ size = strlen(cfg_data_dir) + 6;
char *code_dir = malloc(size);
if (!code_dir) return -3;
- snprintf(code_dir, size, "%s/code", cfg_data_dir);
+ snprintf(code_dir, size, "%s/code\0", cfg_data_dir);
if (stat(code_dir, &fs) != 0) {
if (0 != mkdir(code_dir, S_IRWXU)) {
log_error("Cannot create code dir '%s'\n", code_dir);
@@ -225,7 +225,7 @@
t = strdup(old);
if (!t) return -1;
for (; t; t = s) {
- s = strchr(t, '/');
+ s = strchr(t, '|');
if (s) {
*s = '\0';
++s;
@@ -269,7 +269,7 @@
len = strlen(old) + 1 + strlen(item) + 1;
data = malloc(len);
if (!data) return -1;
- snprintf(data, len, "%s/%s", old, item);
+ snprintf(data, len, "%s|%s", old, item);
e = put_data(db, key, data, strlen(data) + 1);
if (e) return -1;
@@ -303,6 +303,8 @@
if (open_env(&db, APP_DB)) goto out;
+ del_data(db.app, app);
+
list = get_data(db.app, "__apps__", NULL, &e);
if (list) {
@@ -310,11 +312,11 @@
int sa = strlen(app);
k = strstr(list, app);
if (k) {
- if (k[sa] == '/') ++sa;
+ if (k[sa] == '|') ++sa;
memmove(k, k + sa, strlen(k) - sa + 1);
sa = strlen(list);
if (sa > 0) {
- if (list[sa-1] == '/') list[sa-1] = '\0';
+ if (list[sa-1] == '|') list[sa-1] = '\0';
}
e = put_data(db.app, "__apps__", list, strlen(list) + 1);
if (e) goto out;
@@ -344,11 +346,11 @@
int sa = strlen(model);
k = strstr(list, model);
if (k) {
- if (k[sa] == '/') ++sa;
+ if (k[sa] == '|') ++sa;
memmove(k, k + sa, strlen(k) - sa + 1);
sa = strlen(list);
if (sa > 0) {
- if (list[sa-1] == '/') list[sa-1] = '\0';
+ if (list[sa-1] == '|') list[sa-1] = '\0';
}
e = put_data(db.app, app, list, strlen(list) + 1);
if (e) goto out;
Modified: branches/comar-dbus/comar/src/dbus.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 Tue Dec 11 17:05:36 2007
@@ -19,7 +19,50 @@
const char *valid_app_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-+";
const char *valid_model_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
-const char *path_prefix = "/package/";
+
+char *
+strsub(char *str, int start, int end)
+{
+ if (start < 0) {
+ start = strlen(str) + start;
+ }
+ else if (start > strlen(str)) {
+ end = strlen(str);
+ }
+ if (end == 0) {
+ end = strlen(str);
+ }
+ else if (end < 0) {
+ end = strlen(str) + end;
+ }
+ else if (end > strlen(str)) {
+ end = strlen(str);
+ }
+
+ char *new_src, *t;
+ new_src = malloc(end - start + 2);
+ for (t = str + start; t < str + end; t++) {
+ new_src[t - (str + start)] = *t;
+ }
+ new_src[t - (str + start)] = '\0';
+ return new_src;
+}
+
+char *
+strrep(char *str, char old, char new)
+{
+ char *new_str, *t;
+
+ new_str = strdup(str);
+
+ for (t = new_str; *t != '\0'; t++) {
+ if (*t == old) {
+ *t = new;
+ }
+ }
+
+ return new_str;
+}
int
check_file(const char *fname)
@@ -59,15 +102,23 @@
}
int
-in_str(const char chr, const char *str)
+save_file(const char *fname, const char *buffer, size_t size)
{
- int i;
+ /*!
+ @return Returns -1 if file could not be opened for binary writing \n
+ Returns -2 if file could not be written to disc or buffer is empty \n
+ Returns 0 on success
+ */
- for (i = 0; i < strlen(str); i++) {
- if (str[i] == chr) {
- return 1;
- }
+ FILE *f;
+
+ f = fopen(fname, "wb");
+ if (!f) return -1;
+ if (fwrite(buffer, size, 1, f) < 1) {
+ fclose(f);
+ return -2;
}
+ fclose(f);
return 0;
}
@@ -81,7 +132,7 @@
}
for (i = 0; i < strlen(model); i++) {
- if (!in_str(model[i], valid_model_chars)) {
+ if (strchr(valid_model_chars, model[i]) == NULL) {
return 0;
}
}
@@ -98,7 +149,7 @@
}
for (i = 0; i < strlen(app); i++) {
- if (!in_str(app[i], valid_app_chars)) {
+ if (strchr(valid_model_chars, app[i]) == NULL) {
return 0;
}
}
@@ -106,40 +157,6 @@
}
char *
-str_lshift(const char *str, int num)
-{
- char *new_str, *old_str, *t, *t2;
- int size;
-
- size = strlen(str) - num + 1;
- new_str = malloc(size);
-
- for (t = (char *) str + num, t2 = new_str; *t != '\0'; t++, t2++) {
- *t2 = *t;
- }
- *t2 = '\0';
-
- return new_str;
-}
-
-char *
-str_replace(const char *str, const char old, const char new)
-{
- char *new_str, *t, *t2;
- int size;
-
- new_str = strdup(str);
-
- for (t = new_str; *t != '\0'; t++) {
- if (*t == old) {
- *t = new;
- }
- }
-
- return new_str;
-}
-
-char *
get_xml_path(const char *model)
{
char *realpath, *model_escaped, *t, *t2;
@@ -148,7 +165,7 @@
size = strlen(cfg_config_dir) + 1 + strlen("introspections") + 1 + strlen(model) + 5;
realpath = malloc(size);
- model_escaped = (char *) str_replace(model, '.', '_');
+ model_escaped = (char *) strrep(model, '.', '_');
// Generate script path
snprintf(realpath, size, "%s/introspections/%s.xml\0", cfg_config_dir, model_escaped);
@@ -165,7 +182,7 @@
size = strlen(cfg_data_dir) + 1 + strlen("code") + 1 + strlen(model) + 1 + strlen(app) + 4;
realpath = malloc(size);
- model_escaped = (char *) str_replace(model, '.', '_');
+ model_escaped = (char *) strrep(model, '.', '_');
// Generate script path
snprintf(realpath, size, "%s/code/%s_%s.py\0", cfg_data_dir, model_escaped, app);
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 17:05:36 2007
@@ -20,8 +20,9 @@
xml = iks_new("node");
char *t, *s;
- for (t = nodes; t; t = s) {
- s = strchr(t, '/');
+ t = strdup(nodes);
+ for (; t; t = s) {
+ s = strchr(t, '|');
if (s) {
*s = '\0';
++s;
@@ -56,8 +57,9 @@
snprintf(*intros, 7, "<node>\0");
char *t, *s;
- for (t = models; t; t = s) {
- s = strchr(t, '/');
+ t = strdup(models);
+ for (; t; t = s) {
+ s = strchr(t, '|');
if (s) {
*s = '\0';
++s;
@@ -81,3 +83,30 @@
return 0;
}
+
+int
+xml_export_system(char **intros)
+{
+ int size;
+ char *model_xml;
+
+ size = strlen("<node></node>") + 1;
+ *intros = malloc(size);
+ snprintf(*intros, 7, "<node>\0");
+
+ model_xml = (char*) load_file(get_xml_path("Comar"), NULL);
+
+ if (model_xml == NULL) {
+ log_error("Missing introspection data for 'Comar'\n");
+ return 1;
+ }
+
+ size = size + strlen(model_xml);
+ *intros = (char *) realloc(*intros, size);
+ strncat(*intros, model_xml, strlen(model_xml));
+ free(model_xml);
+
+ strncat(*intros, "</node>", 7);
+
+ return 0;
+}
Modified: branches/comar-dbus/tests/run.sh
=================================================================
--- branches/comar-dbus/tests/run.sh (original)
+++ branches/comar-dbus/tests/run.sh Tue Dec 11 17:05:36 2007
@@ -1 +1,12 @@
-sudo ../comar-dbus --print --configdir=../etc --datadir=data --debug=all
+#!/bin/sh
+
+if [[ ${UID} != 0 ]]
+then
+ echo "You must be root";
+ exit 1;
+fi
+
+rm -rf data/
+
+echo "Running Comar..."
+../comar/comar-dbus --print --configdir=../comar/etc --datadir=data --debug=full
Uludag-commits mesaj listesiyle ilgili
daha fazla bilgi