From: <svn...@op...> - 2009-10-30 21:09:47
|
Author: dgollub Date: Fri Oct 30 22:09:28 2009 New Revision: 5894 URL: http://www.opensync.org/changeset/5894 Log: API changes for osync_client_run_and_block() Added parameter: OSyncError** which gets set on any error. Additionally the return type changed to osync_bool. The return value is FALSE on any error, on success TRUE. New OSyncClient interfaces: * osync_client_{get,set}_plugin * osync_client_{get,set}_pipe_path This changes allow to assemble plugins which run as an external process: OSYNC_START_TYPE_EXTERNAL Such plugins assemble OSyncPlugin* and OSyncClient* and need to set the pipe path to the "pluginpipe" in the member direcotry. Modified: trunk/opensync.sym trunk/opensync/client/opensync_client.c trunk/opensync/client/opensync_client.h trunk/opensync/client/opensync_client_internals.h trunk/opensync/client/opensync_client_private.h trunk/opensync/client/osplugin.c Modified: trunk/opensync.sym ============================================================================== --- trunk/opensync.sym Fri Oct 23 20:12:54 2009 (r5893) +++ trunk/opensync.sym Fri Oct 30 22:09:28 2009 (r5894) @@ -53,12 +53,16 @@ osync_change_set_objtype osync_change_set_uid osync_change_unref +osync_client_get_pipe_path +osync_client_get_plugin osync_client_new osync_client_ref osync_client_run osync_client_run_and_block osync_client_set_incoming_queue osync_client_set_outgoing_queue +osync_client_set_pipe_path +osync_client_set_plugin osync_client_unref osync_context_new osync_context_ref Modified: trunk/opensync/client/opensync_client.c ============================================================================== --- trunk/opensync/client/opensync_client.c Fri Oct 23 20:12:54 2009 (r5893) +++ trunk/opensync/client/opensync_client.c Fri Oct 30 22:09:28 2009 (r5894) @@ -1705,6 +1705,42 @@ } } +void osync_client_set_plugin(OSyncClient *client, OSyncPlugin *plugin) +{ + osync_return_if_fail(client); + osync_return_if_fail(plugin); + + if (client->plugin) + osync_plugin_unref(client->plugin); + + + client->plugin = osync_plugin_ref(plugin); +} + +OSyncPlugin *osync_client_get_plugin(OSyncClient *client) +{ + osync_return_val_if_fail(client, NULL); + return client->plugin; +} + +void osync_client_set_pipe_path(OSyncClient *client, const char *pipe_path) +{ + osync_return_if_fail(client); + osync_return_if_fail(pipe_path); + + if (client->pipe_path) + osync_free(client->pipe_path); + + + client->pipe_path = osync_strdup(pipe_path); +} + +const char *osync_client_get_pipe_path(OSyncClient *client) +{ + osync_return_val_if_fail(client, NULL); + return client->pipe_path; +} + osync_bool osync_client_set_incoming_queue(OSyncClient *client, OSyncQueue *incoming, OSyncError **error) { osync_queue_set_message_handler(incoming, _osync_client_message_handler, client); @@ -1739,21 +1775,94 @@ return FALSE; } -void osync_client_run_and_block(OSyncClient *client) +osync_bool osync_client_run_and_block(OSyncClient *client, OSyncError **error) { + + if (!osync_client_setup_pipes(client, NULL, error)) + goto error; + + if (!osync_client_connect_pipes(client, error)) + goto error; + client->syncloop = g_main_loop_new(client->context, TRUE); g_main_loop_run(client->syncloop); + + return TRUE; + +error: + return FALSE; } osync_bool osync_client_run(OSyncClient *client, OSyncError **error) { + if (!osync_client_setup_pipes(client, NULL, error)) + goto error; + + if (!osync_client_connect_pipes(client, error)) + goto error; + client->thread = osync_thread_new(client->context, error); if (!client->thread) - return FALSE; + goto error; osync_thread_start(client->thread); return TRUE; + +error: + return FALSE; +} + +osync_bool osync_client_setup_pipes(OSyncClient *client, const char *pipe_path, OSyncError **error) +{ + OSyncQueue *incoming = NULL; + + const char *path = NULL; + + if (pipe_path) { + path = pipe_path; + } else if (client->pipe_path) { + path = client->pipe_path; + } else { + /* If there are no pipes - which is perfectly fine - this is just NOP */ + return TRUE; + } + + /* Create connection pipes **/ + incoming = osync_queue_new(path, error); + if (!incoming) + goto error; + + if (!osync_queue_create(incoming, error)) + goto error_free_queue; + + if (!osync_client_set_incoming_queue(client, incoming, error)) + goto error_remove_queue; + + osync_queue_unref(incoming); + + return TRUE; + +error_remove_queue: + osync_queue_remove(incoming, NULL); +error_free_queue: + osync_queue_unref(incoming); +error: + return FALSE; +} + +osync_bool osync_client_connect_pipes(OSyncClient *client, OSyncError **error) +{ + /* Nop pipes are perfeclty fine - this function does NOP in this case */ + if (!client->incoming) + return TRUE; + + /* Skip if queues already connected - this is different for each plugin start type */ + if (osync_queue_is_connected(client->incoming)) + return TRUE; + + /* We now connect to our incoming queue */ + return osync_queue_connect(client->incoming, OSYNC_QUEUE_RECEIVER, error); } static gboolean osyncClientConnectCallback(gpointer data) @@ -1762,8 +1871,9 @@ client = data; osync_trace(TRACE_INTERNAL, "About to connect to the incoming queue"); + /* We now connect to our incoming queue */ - if (!osync_queue_connect(client->incoming, OSYNC_QUEUE_RECEIVER, NULL)) + if (!osync_client_connect_pipes(client, NULL)) return TRUE; return FALSE; @@ -1772,23 +1882,15 @@ osync_bool osync_client_run_external(OSyncClient *client, char *pipe_path, OSyncPlugin *plugin, OSyncError **error) { - OSyncQueue *incoming = NULL; GSource *source = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %s, %p, %p)", __func__, client, pipe_path, plugin, error); - /* Create connection pipes **/ - incoming = osync_queue_new(pipe_path, error); - if (!incoming) + + if (!osync_client_setup_pipes(client, pipe_path, error)) goto error; - if (!osync_queue_create(incoming, error)) - goto error_free_queue; - - if (!osync_client_set_incoming_queue(client, incoming, error)) - goto error_remove_queue; - client->thread = osync_thread_new(client->context, error); if (!client->thread) - goto error_remove_queue; + goto error; osync_thread_start(client->thread); @@ -1799,15 +1901,9 @@ g_source_set_callback(source, osyncClientConnectCallback, client, NULL); g_source_attach(source, client->context); - osync_queue_unref(incoming); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; - - error_remove_queue: - osync_queue_remove(incoming, NULL); - error_free_queue: - osync_queue_unref(incoming); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; Modified: trunk/opensync/client/opensync_client.h ============================================================================== --- trunk/opensync/client/opensync_client.h Fri Oct 23 20:12:54 2009 (r5893) +++ trunk/opensync/client/opensync_client.h Fri Oct 30 22:09:28 2009 (r5894) @@ -28,7 +28,14 @@ OSYNC_EXPORT osync_bool osync_client_set_incoming_queue(OSyncClient *client, OSyncQueue *incoming, OSyncError **error); OSYNC_EXPORT osync_bool osync_client_set_outgoing_queue(OSyncClient *client, OSyncQueue *outgoing, OSyncError **error); -OSYNC_EXPORT void osync_client_run_and_block(OSyncClient *client); +OSYNC_EXPORT void osync_client_set_plugin(OSyncClient *client, OSyncPlugin *plugin); +OSYNC_EXPORT OSyncPlugin *osync_client_get_plugin(OSyncClient *client); + +OSYNC_EXPORT void osync_client_set_pipe_path(OSyncClient *client, const char *pipe_path); +OSYNC_EXPORT const char *osync_client_get_pipe_path(OSyncClient *client); + +OSYNC_EXPORT osync_bool osync_client_run_and_block(OSyncClient *client, OSyncError **error); OSYNC_EXPORT osync_bool osync_client_run(OSyncClient *client, OSyncError **error); + #endif /*OPENSYNC_CLIENT_H_*/ Modified: trunk/opensync/client/opensync_client_internals.h ============================================================================== --- trunk/opensync/client/opensync_client_internals.h Fri Oct 23 20:12:54 2009 (r5893) +++ trunk/opensync/client/opensync_client_internals.h Fri Oct 30 22:09:28 2009 (r5894) @@ -28,4 +28,7 @@ OSYNC_TEST_EXPORT osync_bool osync_client_run_external(OSyncClient *client, char *pipe_path, OSyncPlugin *plugin, OSyncError **error); +osync_bool osync_client_setup_pipes(OSyncClient *client, const char *pipe_path, OSyncError **error); +osync_bool osync_client_connect_pipes(OSyncClient *client, OSyncError **error); + #endif /*OPENSYNC_CLIENT_INTERNALS_H_*/ Modified: trunk/opensync/client/opensync_client_private.h ============================================================================== --- trunk/opensync/client/opensync_client_private.h Fri Oct 23 20:12:54 2009 (r5893) +++ trunk/opensync/client/opensync_client_private.h Fri Oct 30 22:09:28 2009 (r5894) @@ -34,6 +34,9 @@ OSyncFormatEnv *format_env; void *plugin_data; OSyncThread *thread; + + /* pipe path for the queue */ + char *pipe_path; }; #endif /*OPENSYNC_CLIENT_PRIVATE_H_*/ Modified: trunk/opensync/client/osplugin.c ============================================================================== --- trunk/opensync/client/osplugin.c Fri Oct 23 20:12:54 2009 (r5893) +++ trunk/opensync/client/osplugin.c Fri Oct 30 22:09:28 2009 (r5894) @@ -123,7 +123,8 @@ osync_queue_unref(incoming); } - osync_client_run_and_block(client); + if (!osync_client_run_and_block(client, &error)) + goto error; osync_client_unref(client); |