missed a few files

SVN revision: 26082
This commit is contained in:
rephorm 2006-09-24 07:28:07 +00:00 committed by rephorm
parent 16f3aae0c9
commit ce507ae550
4 changed files with 384 additions and 0 deletions

View File

@ -0,0 +1,41 @@
dnl AC_ABSTRACT_SOCKET_TEST(ACTION_IF_FOUND, ACTION_IF_NOT_FOUND)
dnl test if a system supports the abstract socket namespace
dnl by rephorm
AC_DEFUN([AC_ABSTRACT_SOCKET_TEST], [
AC_MSG_CHECKING(abstract sockets)
AC_LANG_PUSH(C)
AC_RUN_IFELSE([AC_LANG_PROGRAM(
[[
// headers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
]],
[[
// main fn
#define ABS_SUN_LEN(s, path) (strlen(path) + 1 + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
int fd;
struct sockaddr_un sock;
char *tmp;
char *name = "/ecore/dbus/abstract/test";
sock.sun_family = AF_UNIX;
snprintf(sock.sun_path, sizeof(sock.sun_path), ".%s", name);
sock.sun_path[0] = '\0';
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (bind(fd, (struct sockaddr *)&sock, ABS_SUN_LEN(&sock, name)) < 0)
{
printf("Failed to bind to abstract socket.\n");
exit(1);
}
printf ("connected\n");
exit(0);
]])],
[$1],
[$2])
])

View File

@ -7,3 +7,4 @@ ecore_evas_test
ecore_test
ecore_dbus_test
ecore_dbus_hal_test
ecore_dbus_receiver_test

View File

@ -0,0 +1,109 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include "ecore_dbus_test.h"
#ifdef BUILD_ECORE_DBUS
static int ecore_dbus_event_server_add(void *udata, int ev_type, void *ev);
static int ecore_dbus_event_server_del(void *udata, int ev_type, void *ev);
static int ecore_dbus_event_method_call(void *udata, int ev_type, void *ev);
static void ecore_dbus_method_add_match_cb(void *data, Ecore_DBus_Method_Return *reply);
static void ecore_dbus_method_error_cb(void *data, const char *error);
static Ecore_DBus_Server *svr = NULL;
int
main(int argc, char **argv)
{
ecore_dbus_init();
svr = ecore_dbus_server_session_connect(NULL);
if (!svr)
{
printf("Couldn't connect to dbus system server!\n");
}
else
{
int i = 0;
Ecore_Event_Handler *handler[3];
printf("Connected!\n");
handler[i++] = ecore_event_handler_add(ECORE_DBUS_EVENT_SERVER_ADD,
ecore_dbus_event_server_add, NULL);
handler[i++] = ecore_event_handler_add(ECORE_DBUS_EVENT_SERVER_DEL,
ecore_dbus_event_server_del, NULL);
handler[i++] = ecore_event_handler_add(ECORE_DBUS_EVENT_METHOD_CALL,
ecore_dbus_event_method_call, NULL);
ecore_main_loop_begin();
for (i = 0; i < 2; i++)
ecore_event_handler_del(handler[i]);
if (svr) ecore_dbus_server_del(svr);
}
ecore_dbus_shutdown();
return 0;
}
static int
ecore_dbus_event_server_add(void *udata, int ev_type, void *ev)
{
Ecore_DBus_Event_Server_Add *event;
event = ev;
printf("ecore_dbus_event_server_add\n");
ecore_dbus_method_request_name(event->server, "org.enlightenment.Test", 0, NULL, ecore_dbus_method_error_cb, NULL);
ecore_dbus_method_add_match(event->server, "type=method_call,interface=org.enlightenment.Test", ecore_dbus_method_add_match_cb, ecore_dbus_method_error_cb, NULL);
return 0;
}
static int
ecore_dbus_event_method_call(void *udata, int ev_type, void *ev)
{
Ecore_DBus_Event_Method_Call *event;
event = ev;
printf("ecore_dbus_event_method_call\n");
return 1;
}
static int
ecore_dbus_event_server_del(void *udata, int ev_type, void *ev)
{
Ecore_DBus_Event_Server_Del *event;
event = ev;
printf("ecore_dbus_event_server_del\n");
svr = NULL;
ecore_main_loop_quit();
return 0;
}
static void
ecore_dbus_method_add_match_cb(void *data, Ecore_DBus_Method_Return *reply)
{
printf("Match added. Should be listening for method calls now.\n");
}
static void
ecore_dbus_method_error_cb(void *data, const char *error)
{
printf("Error: %s\n", error);
ecore_main_loop_quit();
}
#else
int
main(int argc, const char **argv)
{
printf("Ecore_DBus module not compiled. This program is empty.\n");
return -1;
}
#endif

View File

@ -0,0 +1,233 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include "config.h"
#include "ecore_private.h"
#include "Ecore_DBus.h"
#include "ecore_dbus_private.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
static void
_list_free_cb(void *data)
{
if (data) free(data);
}
Ecore_DBus_Address *
ecore_dbus_address_new()
{
Ecore_DBus_Address *a;
a = calloc(1, sizeof(Ecore_DBus_Address));
if (!a) return NULL;
a->keys = ecore_list_new();
ecore_list_set_free_cb(a->keys, _list_free_cb);
a->vals = ecore_list_new();
ecore_list_set_free_cb(a->vals, _list_free_cb);
return a;
}
void
ecore_dbus_address_free(Ecore_DBus_Address *address)
{
if (!address) return;
ecore_list_destroy(address->keys);
ecore_list_destroy(address->vals);
if (address->transport) free(address->transport);
free(address);
}
/**
* Parse an address into an array of Ecore_DBus_Address structs
*/
Ecore_List *
ecore_dbus_address_parse(const char *address)
{
Ecore_List *alist = NULL;
Ecore_DBus_Address *a = NULL;
char *addcpy;
char *p;
addcpy = strdup(address);
p = addcpy;
char *start;
char *transport = p;
char *key = NULL;
char *val = NULL;
int error = 0;
alist = ecore_list_new();
ecore_list_set_free_cb(alist, ECORE_FREE_CB(ecore_dbus_address_free));
while(1)
{
if (!a)
{
start = p;
a = ecore_dbus_address_new();
if (!a) { error = 1; break; }
}
if (!*p || *p == ';' || *p == ',')
{
/* append value */
char sep = *p;
if (!val)
{
if (p != start) error = 1;
break;
}
*p = '\0';
ecore_list_append(a->vals, strdup(val));
val = NULL;
if (sep == ',')
{
key = p + 1;
}
else
{
/* append address to list */
ecore_list_append(alist, a);
a = NULL;
if (!sep) break; /* end of string */
transport = p + 1;
}
}
else if (*p == '=')
{
/* append key */
if (!key) { error = 1; break; }
*p = '\0';
ecore_list_append(a->keys, strdup(key));
key = NULL;
val = p + 1;
}
else if (*p == ':')
{
/* append transport */
if (!transport) { error = 1; break; }
*p = '\0';
a->transport = strdup(transport);
transport = NULL;
key = p + 1;
}
p++;
}
if (error)
{
ecore_list_destroy(alist);
alist = NULL;
}
free(addcpy);
return alist;
}
char *
ecore_dbus_address_value_get(Ecore_DBus_Address *address, char *key)
{
int i;
char *s;
if (!key) return NULL;
ecore_list_goto_first(address->keys);
i = 0;
while((s = ecore_list_next(address->keys)))
{
if (!strcmp(key, s))
{
return ecore_list_goto_index(address->vals, i);
}
i++;
}
return NULL;
}
/**
* Connect to the first successful server in a list of addresses.
*/
EAPI Ecore_DBus_Server *
ecore_dbus_address_list_connect(Ecore_List *addrs, const void *data)
{
Ecore_DBus_Address *addr;
ecore_list_goto_first(addrs);
/* try each listed address in turn */
while ((addr = ecore_list_next(addrs)))
{
Ecore_DBus_Server *svr;
svr = ecore_dbus_address_connect(addr, data);
if (svr) return svr;
}
return NULL;
}
/**
* Connect to a server by its Ecore_DBus_Address
*/
EAPI Ecore_DBus_Server *
ecore_dbus_address_connect(Ecore_DBus_Address *addr, const void *data)
{
const char *name;
int type;
int port;
if (!strcmp(addr->transport, "unix"))
{
type = ECORE_CON_LOCAL_SYSTEM;
name = ecore_dbus_address_value_get(addr, "path");
#ifdef HAVE_ABSTRACT_SOCKETS
if (!name)
{
name = ecore_dbus_address_value_get(addr, "abstract");
type = ECORE_CON_LOCAL_ABSTRACT;
}
#endif
if (!name) return NULL;
port = -1;
}
else if (!strcmp(addr->transport, "tcp"))
{
/* XXX implement (and verify transport name is actually 'tcp') */
return NULL;
}
else
{
return NULL;
}
return ecore_dbus_server_connect(type, name, port, data);
}
void
ecore_dbus_print_address_list(Ecore_List *addresses)
{
Ecore_DBus_Address *a;
ecore_list_goto_first(addresses);
while((a = ecore_list_next(addresses)))
{
char *k, *v;
printf("Transport: %s\n", a->transport);
ecore_list_goto_first(a->keys);
ecore_list_goto_first(a->vals);
k = ecore_list_next(a->keys);
v = ecore_list_next(a->vals);
while (k || v)
{
printf(" %s => %s\n", k, v);
k = ecore_list_next(a->keys);
v = ecore_list_next(a->vals);
}
}
}