Enlightenment CVS committal Author : lordchaos Project : e17 Module : apps/evfs
Dir : e17/apps/evfs/src/lib Modified Files: libevfs.c Log Message: * Work on serializing/deserializing commands to daemon * Event engine work =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/lib/libevfs.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- libevfs.c 15 Aug 2005 19:53:57 -0000 1.3 +++ libevfs.c 16 Aug 2005 05:44:22 -0000 1.4 @@ -1,10 +1,79 @@ #include "evfs.h" + +Ecore_List* client_list = NULL; +static int libevfs_registered_callback = 0; + +evfs_connection* evfs_get_connection_for_id(int id) { + evfs_connection* conn; + + ecore_list_goto_first(client_list); + + while ( (conn = ecore_list_next(client_list))) { + if (conn->id == id) return conn; + } + + return NULL; + +} + +int evfs_server_data (void* data, int type, void* event) { + printf("Got message from server %d..\n", ((Ecore_Ipc_Event_Server_Data*)event)->major); + + Ecore_Ipc_Event_Server_Data *e; + if ((e = (Ecore_Ipc_Event_Server_Data *) event)) { + /*Special case, if it's an id notify, we can't really id the client without it*/ + + if (e->major == EVFS_EV_NOTIFY_ID) { + /*We have an id, assign it to the most recent client*/ + /*This assumes we don't drop anything - this could be dangerous*/ + + evfs_connection* client; + ecore_list_goto_first(client_list); + if ( (client = ecore_list_next(client_list))) { + + + /*We have a client, let's see if it needs an id*/ + if (client->id == MAX_CLIENT) { + memcpy(&client->id, e->data, sizeof(unsigned long)); + printf("This client is assigned id %ld\n", client->id); + } else { + printf(stderr, "Error, client already has an assigned id. Dropped packet?\n"); + return 1; + } + } + + } else { + + /*Get the connection associated with this ipc ref*/ + /*we should probably use a hash here, but we aren't, for two reasons: + * 1: We don't even have a key until the server assigns us one + * 2: Most clients will only have one connection, giving us O(n) (worst) -> O(1) (best) + */ + + evfs_connection* conn = evfs_get_connection_for_id(e->ref); + } + } +} + evfs_connection* evfs_connect() { ecore_init(); ecore_ipc_init(); evfs_connection* connection = NEW(evfs_connection); + connection->id = MAX_CLIENT; + connection->prog_event = NULL; + + if (!libevfs_registered_callback) { + libevfs_registered_callback = 1; + fprintf(stderr, "Registering callback at client..\n"); + ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, evfs_server_data, NULL); + client_list = ecore_list_new(); + + ecore_list_append(client_list, connection); + } else { + ecore_list_prepend(client_list, connection); + } if ( !(connection->server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, EVFS_IPC_TITLE, 0, NULL)) ) { fprintf(stderr, "Cannot connect to evfs server with '%s'..\n", EVFS_IPC_TITLE); @@ -14,6 +83,9 @@ } + + + return connection; } ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs