[RFC][PATCH] External command in plugin configuration file

View: New views
2 Messages — Rating Filter:   Alert me  

[RFC][PATCH] External command in plugin configuration file

by Henrik /KaarPoSoft-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

Following Daniel's checkin of the client and example code for external
plugin, here is a patch (on -r5895) which allows a member to set an
ExternalCommand in the plugin configuration file. This command will be
executed by the proxy to start up the external process.

Your comments would be most appreciated.

/Henrik


Index: misc/schemas/plugin_config.xsd
===================================================================
--- misc/schemas/plugin_config.xsd (revision 5895)
+++ misc/schemas/plugin_config.xsd (working copy)
@@ -9,6 +9,7 @@
         <xsd:element maxOccurs="1" minOccurs="0" name="Connection" type="Connection"/>
         <xsd:element maxOccurs="1" minOccurs="0" name="Localization" type="Localization"/>
         <xsd:element maxOccurs="1" minOccurs="0" name="Resources" type="Resources"/>
+        <xsd:element maxOccurs="1" minOccurs="0" name="ExternalPlugin" type="ExternalPlugin"/>
       </xsd:sequence>
       <xsd:attribute name="version" type="xsd:string"/>
     </xsd:complexType>
@@ -164,4 +165,10 @@
     </xsd:all>
   </xsd:complexType>
 
+  <xsd:complexType name="ExternalPlugin">
+    <xsd:all>
+      <xsd:element maxOccurs="1" minOccurs="1" name="ExternalCommand" type="xsd:string" />
+    </xsd:all>
+  </xsd:complexType>
+
 </xsd:schema>
Index: opensync/opensync-plugin.h
===================================================================
--- opensync/opensync-plugin.h (revision 5895)
+++ opensync/opensync-plugin.h (working copy)
@@ -33,6 +33,7 @@
 #include "plugin/opensync_plugin_connection.h"
 #include "plugin/opensync_plugin_localization.h"
 #include "plugin/opensync_plugin_resource.h"
+#include "plugin/opensync_plugin_externalplugin.h"
 #include "plugin/opensync_objtype_sink.h"
 
 OPENSYNC_END_DECLS
Index: opensync/group/opensync_member.c
===================================================================
--- opensync/group/opensync_member.c (revision 5895)
+++ opensync/group/opensync_member.c (working copy)
@@ -832,6 +832,18 @@
  return new_list;
 }
 
+const char *osync_member_get_external_command(OSyncMember *member)
+{
+ osync_assert(member);
+ OSyncError *error;
+ OSyncPluginConfig *config = osync_member_get_config_or_default(member, &error);
+ if (config) {
+ OSyncPluginExternalPlugin *externalplugin = osync_plugin_config_get_externalplugin(config);
+ if (externalplugin) return osync_plugin_externalplugin_get_external_command(externalplugin);
+ }
+ return NULL;
+}
+
 osync_bool osync_member_objtype_enabled(OSyncMember *member, const char *objtype)
 {
  OSyncObjTypeSink *sink = NULL;
Index: opensync/group/opensync_member.h
===================================================================
--- opensync/group/opensync_member.h (revision 5895)
+++ opensync/group/opensync_member.h (working copy)
@@ -334,6 +334,25 @@
  */
 OSYNC_EXPORT osync_bool osync_member_plugin_is_uptodate(OSyncMember *member);
 
+/** @brief Returns the external command of a member
+ *
+ * If the plugin is of type OSYNC_START_TYPE_EXTERNAL, an external command can be executed by OpenSync.
+ * The external_command should be a string in printf format, with one %s.
+ * Before the command is executed, a variant of printf will be called
+ * to replace the %s with the path to the plugin pipe.
+ * The resulting command will be exectued with the glib function
+ * g_spawn_command_line_async.
+ *
+ * The external command is specified in the plugin configuration file for the member, e.g.
+ * <ExternalPlugin><ExternalCommand>the command</ExternalCommand></ExternalPlugin>
+ *
+ * @param plugin Pointer to the plugin
+ * @returns External command of the plugin
+ *
+ */
+OSYNC_EXPORT const char *osync_member_get_external_command(OSyncMember *member);
+
+
 /*@}*/
 
 #endif /* _OPENSYNC_MEMBER_H_ */
Index: opensync/plugin/opensync_plugin_externalplugin_private.h
===================================================================
--- opensync/plugin/opensync_plugin_externalplugin_private.h (revision 0)
+++ opensync/plugin/opensync_plugin_externalplugin_private.h (revision 0)
@@ -0,0 +1,49 @@
+/*
+ * libopensync - A synchronization framework
+ * Copyright (C) 2009  Henrik Kaare Poulsen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#ifndef _OPENSYNC_PLUGIN_EXTERNALPLUGIN_PRIVATE_H_
+#define _OPENSYNC_PLUGIN_EXTERNALPLUGIN_PRIVATE_H_
+
+/**
+ * @defgroup OSyncPluginExternalPluginPrivateAPI OpenSync Plugin ExternalPlugin Private
+ * @ingroup OSyncPluginPrivate
+ */
+
+/*@{*/
+
+/**
+ * @brief Gives information for plugin of type OSYNC_START_TYPE_EXTERNAL
+ **/
+struct OSyncPluginExternalPlugin {
+ /** Command to be executed to start the external process.
+    In printf format; should have one %s
+    which will be replaced with
+    the path of the plugin pipe to the client process
+ */
+ char *external_command;
+
+ /** Object reference counting */
+ int ref_count;
+};
+
+/*@}*/
+
+#endif /* _OPENSYNC_PLUGIN_EXTERNALPLUGIN_PRIVATE_H_ */
+
Index: opensync/plugin/opensync_plugin_externalplugin.c
===================================================================
--- opensync/plugin/opensync_plugin_externalplugin.c (revision 0)
+++ opensync/plugin/opensync_plugin_externalplugin.c (revision 0)
@@ -0,0 +1,75 @@
+/*
+ * libopensync - A synchronization framework
+ * Copyright (C) 2009  Henrik Kaare Poulsen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#include "opensync.h"
+#include "opensync_internals.h"
+
+#include "opensync-plugin.h"
+#include "opensync_plugin_externalplugin_private.h"
+
+OSyncPluginExternalPlugin *osync_plugin_externalplugin_new(OSyncError **error)
+{
+ OSyncPluginExternalPlugin *externalplugin = osync_try_malloc0(sizeof(OSyncPluginExternalPlugin), error);
+ if (!externalplugin)
+ return NULL;
+
+ externalplugin->ref_count = 1;
+
+ return externalplugin;
+}
+
+OSyncPluginExternalPlugin *osync_plugin_externalplugin_ref(OSyncPluginExternalPlugin *externalplugin)
+{
+ osync_assert(externalplugin);
+
+ g_atomic_int_inc(&(externalplugin->ref_count));
+
+ return externalplugin;
+}
+
+void osync_plugin_externalplugin_unref(OSyncPluginExternalPlugin *externalplugin)
+{
+ osync_assert(externalplugin);
+
+ if (g_atomic_int_dec_and_test(&(externalplugin->ref_count))) {
+ if (externalplugin->external_command)
+ osync_free(externalplugin->external_command);
+ osync_free(externalplugin);
+ }
+}
+
+
+const char *osync_plugin_externalplugin_get_external_command(OSyncPluginExternalPlugin *externalplugin)
+{
+ osync_assert(externalplugin);
+ return externalplugin->external_command;
+}
+
+void osync_plugin_externalplugin_set_external_command(OSyncPluginExternalPlugin *externalplugin, const char *external_command)
+{
+ osync_assert(externalplugin);
+
+ if (externalplugin->external_command)
+ osync_free(externalplugin->external_command);
+
+ externalplugin->external_command = osync_strdup(external_command);
+}
+
+
Index: opensync/plugin/opensync_plugin_config_private.h
===================================================================
--- opensync/plugin/opensync_plugin_config_private.h (revision 5895)
+++ opensync/plugin/opensync_plugin_config_private.h (working copy)
@@ -44,6 +44,8 @@
  OSyncPluginLocalization *localization;
  /** List of resource configurations */
  OSyncList *resources;
+ /** External plugin configuration */
+ OSyncPluginExternalPlugin *externalplugin;
 
  /** Flags to store supported config options */
  OSyncPluginConfigSupportedFlags supported;
Index: opensync/plugin/opensync_plugin_config.c
===================================================================
--- opensync/plugin/opensync_plugin_config.c (revision 5895)
+++ opensync/plugin/opensync_plugin_config.c (working copy)
@@ -33,6 +33,7 @@
 #include "opensync_plugin_connection_internals.h"
 #include "opensync_plugin_localization_private.h" /* FIXME: direct access to private header */
 #include "opensync_plugin_resource_private.h" /* FIXME: direct access to private header */
+#include "opensync_plugin_externalplugin_private.h" /* FIXME: direct access to private header */
 
 #include "opensync_plugin_config_private.h"
 #include "opensync_plugin_config_internals.h"
@@ -209,6 +210,47 @@
  return FALSE;
 }
 
+static osync_bool _osync_plugin_config_parse_externalplugin(OSyncPluginConfig *config, xmlNode *cur, OSyncError **error)
+{
+ OSyncPluginExternalPlugin *externalplugin = NULL;
+ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, config, cur, error);
+
+ if (cur == NULL) { // don't set externalplugin if ExternalPlugin tag is empty
+ osync_trace(TRACE_EXIT, "%s", __func__);
+ return TRUE;
+ }
+
+ externalplugin = osync_plugin_externalplugin_new(error);
+ if (!externalplugin)
+ goto error;
+
+ for (; cur != NULL; cur = cur->next) {
+ char *str = NULL;
+ if (cur->type != XML_ELEMENT_NODE)
+ continue;
+
+ str = (char*)xmlNodeGetContent(cur);
+ if (!str)
+ continue;
+
+ if (!xmlStrcmp(cur->name, (const xmlChar *)"ExternalCommand")) {
+ osync_plugin_externalplugin_set_external_command(externalplugin, str);
+ }
+
+ osync_xml_free(str);
+ }
+
+ osync_plugin_config_set_externalplugin(config, externalplugin);
+ osync_plugin_externalplugin_unref(externalplugin);
+
+ osync_trace(TRACE_EXIT, "%s", __func__);
+ return TRUE;
+
+ error:
+ osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
+ return FALSE;
+}
+
 static osync_bool _osync_plugin_config_parse_connection_bluetooth(OSyncPluginConnection *conn, xmlNode *cur, OSyncError **error) {
 
  osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, conn, cur, error);
@@ -728,6 +770,9 @@
  } else if (!xmlStrcmp(cur->name, (const xmlChar *)"Resources")) {
  config->supported |= OPENSYNC_PLUGIN_CONFIG_RESOURCES;
  ret = _osync_plugin_config_parse_resources(config, cur->xmlChildrenNode, error);
+ } else if (!xmlStrcmp(cur->name, (const xmlChar *)"ExternalPlugin")) {
+ config->supported |= OPENSYNC_PLUGIN_CONFIG_EXTERNALPLUGIN;
+ ret = _osync_plugin_config_parse_externalplugin(config, cur->xmlChildrenNode, error);
  } else {
  osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Unknown configuration field \"%s\"", cur->name);
  goto error;
@@ -824,6 +869,28 @@
  return FALSE;
 }
 
+static osync_bool _osync_plugin_config_assemble_externalplugin(xmlNode *cur, OSyncPluginExternalPlugin *externalplugin, OSyncError **error)
+{
+ const char *external_command;
+ xmlNode *node = NULL;
+ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, cur, externalplugin, error);
+
+ node = xmlNewChild(cur, NULL, (xmlChar*)"ExternalPlugin", NULL);
+ if (!node) {
+ osync_error_set(error, OSYNC_ERROR_GENERIC, "No memory left to assemble configuration.");
+ goto error;
+ }
+
+ if ((external_command = osync_plugin_externalplugin_get_external_command(externalplugin)))
+ xmlNewChild(node, NULL, (xmlChar*)"ExternalCommand", (xmlChar*)external_command);
+
+ osync_trace(TRACE_EXIT, "%s", __func__);
+ return TRUE;
+ error:
+ osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
+ return FALSE;
+}
+
 static osync_bool _osync_plugin_config_assemble_connection(xmlNode *cur, OSyncPluginConnection *conn, OSyncError **error)
 {
  char *str;
@@ -1308,6 +1375,9 @@
  config->resources = osync_list_remove(config->resources, res);
  }
 
+ if (config->externalplugin)
+ osync_plugin_externalplugin_unref(config->externalplugin);
+
  if (config->schemadir)
  osync_free(config->schemadir);
 
@@ -1330,6 +1400,7 @@
  OSyncPluginConnection *conn;
  OSyncPluginAuthentication *auth;
  OSyncPluginLocalization *local;
+ OSyncPluginExternalPlugin *externalplugin;
  OSyncList *resources;
  OSyncList *options;
  char *version_str = NULL;
@@ -1382,6 +1453,11 @@
  if (!_osync_plugin_config_assemble_resources(doc->children, resources, error))
  goto error_and_free;
 
+ /* ExternalPlugin */
+ if ((externalplugin = osync_plugin_config_get_externalplugin(config)))
+ if (!_osync_plugin_config_assemble_externalplugin(doc->children, externalplugin, error))
+ goto error_and_free;
+
  xmlSaveFormatFile(path, doc, 1);
 
  osync_xml_free_doc(doc);
@@ -1567,7 +1643,27 @@
  return NULL;
 }
 
+/* External Plugin */
+OSyncPluginExternalPlugin *osync_plugin_config_get_externalplugin(OSyncPluginConfig *config)
+{
+ osync_assert(config);
+ return config->externalplugin;
+}
 
+void osync_plugin_config_set_externalplugin(OSyncPluginConfig *config, OSyncPluginExternalPlugin *externalplugin)
+{
+ osync_assert(config);
+
+ if (config->externalplugin) {
+ osync_plugin_externalplugin_unref(config->externalplugin);
+ config->externalplugin = NULL;
+ }
+
+ if (externalplugin) {
+ config->externalplugin = osync_plugin_externalplugin_ref(externalplugin);
+ }
+}
+
 OSyncPluginConnection *osync_plugin_config_get_connection(OSyncPluginConfig *config)
 {
  osync_assert(config);
Index: opensync/plugin/opensync_plugin_externalplugin.h
===================================================================
--- opensync/plugin/opensync_plugin_externalplugin.h (revision 0)
+++ opensync/plugin/opensync_plugin_externalplugin.h (revision 0)
@@ -0,0 +1,87 @@
+/*
+ * libopensync - A synchronization framework
+ * Copyright (C) 2009  Henrik Kaare Poulsen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#ifndef _OPENSYNC_PLUGIN_EXTERNALPLUGIN_H_
+#define _OPENSYNC_PLUGIN_EXTERNALPLUGIN_H_
+
+/**
+ * @defgroup OSyncPluginExternalPluginAPI OpenSync Plugin ExternalPlugin
+ * @ingroup OSyncPlugin
+ * @brief Functions for configuring external plugin
+ *
+ */
+/*@{*/
+
+
+/** @brief Create a new OSyncPluginExternalPlugin object
+ *
+ * @param error Pointer to an error struct
+ * @returns the newly created object, or NULL in case of an error.
+ *
+ */
+OSYNC_EXPORT OSyncPluginExternalPlugin *osync_plugin_externalplugin_new(OSyncError **error);
+
+/** @brief Decrease the reference count on an OSyncPluginExternalPlugin object
+ *
+ * @param external_plugin Pointer to the OSyncPluginExternalPlugin object
+ *
+ */
+OSYNC_EXPORT void osync_plugin_externalplugin_unref(OSyncPluginExternalPlugin *external_plugin);
+
+/** @brief Increase the reference count on an OSyncPluginExternalPlugin object
+ *
+ * @param external_plugin Pointer to the OSyncPluginExternalPlugin object
+ * @returns The OSyncPluginExternalPlugin object passed in
+ *
+ */
+OSYNC_EXPORT OSyncPluginExternalPlugin *osync_plugin_externalplugin_ref(OSyncPluginExternalPlugin *external_plugin);
+
+
+/** @brief Get the command to start the external plugin process
+ *
+ * @param external_plugin Pointer to the OSyncPluginExternalPlugin object
+ * @returns the external command or NULL if not set
+ *
+ */
+OSYNC_EXPORT const char *osync_plugin_externalplugin_get_external_command(OSyncPluginExternalPlugin *external_plugin);
+
+/** @brief Set the command to start the external plugin process
+ *
+ * If the plugin is of type OSYNC_START_TYPE_EXTERNAL, an external command can be executed by OpenSync.
+ * The external_command should be a string in printf format, with one %s.
+ * Before the command is executed, a variant of printf will be called
+ * to replace the %s with the path to the plugin pipe.
+ * The resulting command will be exectued with the glib function
+ * g_spawn_command_line_async.
+ *
+ * Example: "thunderbird -mozilla-sync %s"
+ *
+ * @param external_plugin Pointer to the OSyncPluginExternalPlugin object
+ * @param external_command The external command to set
+ *
+ */
+OSYNC_EXPORT void osync_plugin_externalplugin_set_external_command(OSyncPluginExternalPlugin *external_plugin, const char *external_command);
+
+
+
+/*@}*/
+
+#endif /*_OPENSYNC_PLUGIN_EXTERNALPLUGIN_H_*/
+
Index: opensync/plugin/opensync_plugin_config.h
===================================================================
--- opensync/plugin/opensync_plugin_config.h (revision 5895)
+++ opensync/plugin/opensync_plugin_config.h (working copy)
@@ -47,7 +47,9 @@
  /** Resources */
  OPENSYNC_PLUGIN_CONFIG_RESOURCES = (1 << 3),
  /** Connection options */
- OPENSYNC_PLUGIN_CONFIG_CONNECTION = (1 << 4)
+ OPENSYNC_PLUGIN_CONFIG_CONNECTION = (1 << 4),
+ /** External Plugin */
+ OPENSYNC_PLUGIN_CONFIG_EXTERNALPLUGIN = (1 << 5)
 } OSyncPluginConfigSupportedFlag;
 
 /** @brief Set of OSyncPluginConfigSupportedFlags
@@ -217,6 +219,21 @@
  */
 OSYNC_EXPORT void osync_plugin_config_set_connection(OSyncPluginConfig *config, OSyncPluginConnection *connection);
 
+/* External Plugin */
+/**@brief Get the external plugin settings from a config
+ *
+ * @param config An OSyncPluginConfig
+ * @returns an OSyncPluginExternalPlugin with the details of the external plugin or NULL if no external plugin settings configured
+ */
+OSYNC_EXPORT OSyncPluginExternalPlugin *osync_plugin_config_get_externalplugin(OSyncPluginConfig *config);
+
+/**@brief Set the external plugin configuration
+ *
+ * @param config An OSyncPluginConfig
+ * @param authentication The new external plugin settings as an OSyncPluginExternalPlugin
+ */
+OSYNC_EXPORT void osync_plugin_config_set_externalplugin(OSyncPluginConfig *config, OSyncPluginExternalPlugin *externalplugin);
+
 /*@}*/
 
 #endif /*_OPENSYNC_PLUGIN_CONFIG_H_*/
Index: opensync/CMakeLists.txt
===================================================================
--- opensync/CMakeLists.txt (revision 5895)
+++ opensync/CMakeLists.txt (working copy)
@@ -60,6 +60,7 @@
    plugin/opensync_plugin_info.c
    plugin/opensync_plugin_localization.c
    plugin/opensync_plugin_resource.c
+   plugin/opensync_plugin_externalplugin.c
    plugin/opensync_objtype_sink.c
    version/opensync_version.c
    xmlformat/opensync_xmlfield.c
Index: opensync/opensync.h
===================================================================
--- opensync/opensync.h (revision 5895)
+++ opensync/opensync.h (working copy)
@@ -222,6 +222,7 @@
 typedef struct OSyncPluginConnection OSyncPluginConnection;
 typedef struct OSyncPluginLocalization OSyncPluginLocalization;
 typedef struct OSyncPluginResource OSyncPluginResource;
+typedef struct OSyncPluginExternalPlugin OSyncPluginExternalPlugin;
 
 /* Engine component */
 typedef struct OSyncEngine OSyncEngine;
Index: opensync/engine/opensync_engine.c
===================================================================
--- opensync/engine/opensync_engine.c (revision 5895)
+++ opensync/engine/opensync_engine.c (working copy)
@@ -773,7 +773,11 @@
  osync_client_proxy_set_context(proxy, engine->context);
  osync_client_proxy_set_change_callback(proxy, _osync_engine_receive_change, engine);
 
- if (!osync_client_proxy_spawn(proxy, osync_plugin_get_start_type(plugin), osync_member_get_configdir(member), error))
+ const char *external_command=NULL;
+ if (osync_plugin_get_start_type(plugin)==OSYNC_START_TYPE_EXTERNAL)
+ external_command=osync_member_get_external_command(member);
+
+ if (!osync_client_proxy_spawn(proxy, osync_plugin_get_start_type(plugin), osync_member_get_configdir(member), external_command, error))
  goto error_free_proxy;
 
  engine->busy = TRUE;
Index: opensync/client/opensync_client_proxy_internals.h
===================================================================
--- opensync/client/opensync_client_proxy_internals.h (revision 5895)
+++ opensync/client/opensync_client_proxy_internals.h (working copy)
@@ -44,7 +44,7 @@
 void osync_client_proxy_set_change_callback(OSyncClientProxy *proxy, change_cb cb, void *userdata);
 OSyncMember *osync_client_proxy_get_member(OSyncClientProxy *proxy);
 
-OSYNC_TEST_EXPORT osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, OSyncError **error);
+OSYNC_TEST_EXPORT osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, const char* external_command, OSyncError **error);
 OSYNC_TEST_EXPORT osync_bool osync_client_proxy_shutdown(OSyncClientProxy *proxy, OSyncError **error);
 
 OSYNC_TEST_EXPORT osync_bool osync_client_proxy_initialize(OSyncClientProxy *proxy, initialize_cb callback, void *userdata, const char *formatdir, const char *plugindir, const char *plugin, const char *groupname, const char *configdir, OSyncPluginConfig *config, OSyncError **error);
Index: opensync/client/opensync_client_proxy.c
===================================================================
--- opensync/client/opensync_client_proxy.c (revision 5895)
+++ opensync/client/opensync_client_proxy.c (working copy)
@@ -952,7 +952,7 @@
  return proxy->member;
 }
 
-osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, OSyncError **error)
+osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, const char* external_command, OSyncError **error)
 {
  OSyncQueue *read1 = NULL;
  OSyncQueue *read2 = NULL;
@@ -1080,6 +1080,22 @@
  goto error;
  } else {
  name = osync_strdup_printf("%s%cpluginpipe", path, G_DIR_SEPARATOR);
+
+ if (external_command) {
+ char *command = osync_strdup_printf(external_command, name);
+ osync_trace(TRACE_INTERNAL, "g_spawn_command_line_async(%s)", command);
+ GError *gerror = NULL;
+ gboolean f = g_spawn_command_line_async(command, &gerror);
+ if (!f) {
+ osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to g_spawn_command_line_async(%s): %s", command, gerror->message);
+ g_error_free (gerror);
+ osync_free(command);
+ goto error;
+ }
+ osync_free(command);
+ }
+
+
  proxy->outgoing = osync_queue_new(name, error);
  osync_free(name);
  if (!proxy->outgoing)
Index: tests/client-tests/check_proxy.c
===================================================================
--- tests/client-tests/check_proxy.c (revision 5895)
+++ tests/client-tests/check_proxy.c (working copy)
@@ -39,7 +39,7 @@
  fail_unless(proxy != NULL, NULL);
  fail_unless(error == NULL, NULL);
 
- fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL);
+ fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL);
  fail_unless(error == NULL, NULL);
 
  fail_unless(osync_client_proxy_shutdown(proxy, &error), NULL);
@@ -110,7 +110,7 @@
  fail_unless(proxy != NULL, NULL);
  fail_unless(error == NULL, NULL);
 
- fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL);
+ fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL);
  fail_unless(error == NULL, NULL);
 
  OSyncPluginConfig *config = simple_plugin_config(NULL, "data1", "mockobjtype1", "mockformat1", NULL);
@@ -159,7 +159,7 @@
  fail_unless(proxy != NULL, NULL);
  fail_unless(error == NULL, NULL);
 
- fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL);
+ fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL);
  fail_unless(error == NULL, NULL);
 
  OSyncPluginConfig *config = simple_plugin_config(NULL, "data1", "mockobjtype1", "mockformat1", NULL);
@@ -225,7 +225,7 @@
  fail_unless(proxy != NULL, NULL);
  fail_unless(error == NULL, NULL);
 
- fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, &error), NULL);
+ fail_unless(osync_client_proxy_spawn(proxy, OSYNC_START_TYPE_THREAD, NULL, NULL, &error), NULL);
  fail_unless(error == NULL, NULL);
 
  OSyncPluginConfig *config = simple_plugin_config(NULL, "data1", "mockobjtype1", "mockformat1", NULL);

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Opensync-devel mailing list
Opensync-devel@...
https://lists.sourceforge.net/lists/listinfo/opensync-devel

Re: [RFC][PATCH] External command in plugin configuration file

by Daniel Gollub-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Saturday 31 October 2009 11:01:33 am Henrik /KaarPoSoft wrote:
> Following Daniel's checkin of the client and example code for external
> plugin, here is a patch (on -r5895) which allows a member to set an
> ExternalCommand in the plugin configuration file. This command will be
> executed by the proxy to start up the external process.
>
> Your comments would be most appreciated.
>

One questions regarding the API:

osync_member_get_external_command()

Is there any reason to export this function to the public API? Our goal should
be to have only a small number of public API interfaces .. so it's easier to
maintain and to keep the API stable .. currently i don't see any reason to put
this inside opensync_member.h

Instead i would suggest to move this into osync_member_internals.h and use
OSYNC_TEST_EXPORT instead .. not OSYNC_EXPORT. So this function is still
avaibale for the osync_engine.c code and for unittests...

Beside this the patch looks pretty good to me ...

JFYI, we have a unit test to avoid API breaks - if you add new public
Interfaces you need to modifiy following file: trunk/opensync.sym

Just add by hand the function name - sorted. And test with:
ctest -R symbol -V

Currently it fails with your patch, due to missing entries:


-----8<----
332a333
> osync_member_get_external_command <------------- IGNORE this!
513a515
> osync_plugin_config_get_externalplugin
522a525
> osync_plugin_config_set_externalplugin
568a572,576
> osync_plugin_externalplugin_get_external_command
> osync_plugin_externalplugin_new
> osync_plugin_externalplugin_ref
> osync_plugin_externalplugin_set_external_command
> osync_plugin_externalplugin_unref
-- Process completed
***Failed

0% tests passed, 1 tests failed out of 1

The following tests FAILED:
          1 - symbols (Failed)
------->8----

So you need to add follwing lines to opensync.sym:

osync_plugin_config_get_externalplugin
osync_plugin_config_set_externalplugin

osync_plugin_externalplugin_get_external_command
osync_plugin_externalplugin_new
osync_plugin_externalplugin_ref
osync_plugin_externalplugin_set_external_command
osync_plugin_externalplugin_unref


Please move osync_member_get_external_command() to opensync_member_internals.h
and adapt opensync.sym commit your modifications.

Thanks for your contribution!

Best Regards,
Daniel

--
Daniel Gollub                        Geschaeftsfuehrer: Ralph Dehner
FOSS Developer                       Unternehmenssitz:  Vohburg
B1 Systems GmbH                      Amtsgericht:       Ingolstadt
Mobil: +49-(0)-160 47 73 970         Handelsregister:   HRB 3537
EMail: gollub@...          http://www.b1-systems.de

Adresse: B1 Systems GmbH, Osterfeldstraße 7, 85088 Vohburg
http://pgpkeys.pca.dfn.de/pks/lookup?op=get&search=0xED14B95C2F8CA78D


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Opensync-devel mailing list
Opensync-devel@...
https://lists.sourceforge.net/lists/listinfo/opensync-devel

signature.asc (204 bytes) Download Attachment