00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "opensync.h"
00022 #include "opensync_internals.h"
00023
00024 #include "opensync-ipc.h"
00025 #include "opensync-client.h"
00026
00027 static void usage (int ecode)
00028 {
00029 fprintf (stderr, "This is the opensync sync client.\n\n");
00030 fprintf (stderr, "The purpose of this tool is,to allow plugin to run in its own process\n");
00031 fprintf (stderr, "It is normally started by OpenSync. But you can start it yourself, for\n");
00032 fprintf (stderr, "debugging purposes (in gdb for example).\n\n");
00033 fprintf (stderr, "Usage:\n");
00034 fprintf (stderr, "osplugin <PipePath>\n\n");
00035 fprintf (stderr, "The pipe path tells the plugin, where to create the listing pipe.\n");
00036 fprintf (stderr, "The pipe is normally created in the member directory with the name\n");
00037 fprintf (stderr, "\"pluginpipe\"\n");
00038 exit (ecode);
00039 }
00040
00053 int main(int argc, char **argv)
00054 {
00055 osync_bool usePipes = FALSE;
00056 OSyncError *error = NULL;
00057 char *pipe_path = NULL;
00058 int read_fd = 0;
00059 int write_fd = 0;
00060 OSyncQueue *incoming = NULL;
00061 OSyncQueue *outgoing = NULL;
00062 OSyncClient *client = NULL;
00063
00064 osync_trace(TRACE_ENTRY, "%s(%i, %p)", __func__, argc, argv);
00065
00066 if (argc != 2 && argc != 4)
00067 usage(0);
00068 client = osync_client_new(&error);
00069 if (!client)
00070 goto error;
00071
00072 if (!strcmp (argv[1], "-f")) {
00073 usePipes = TRUE;
00074
00075
00076 read_fd = atoi(argv[2]);
00077 write_fd = atoi(argv[3]);
00078 } else
00079 pipe_path = argv[1];
00080
00081 if (usePipes) {
00082
00083 incoming = osync_queue_new_from_fd(read_fd, &error);
00084 if (!incoming)
00085 goto error;
00086
00087 outgoing = osync_queue_new_from_fd(write_fd, &error);
00088 if (!outgoing)
00089 goto error;
00090
00091
00092 if (!osync_queue_connect(incoming, OSYNC_QUEUE_RECEIVER, &error))
00093 goto error;
00094
00095
00096 if (!osync_queue_connect(outgoing, OSYNC_QUEUE_SENDER, &error))
00097 goto error;
00098
00099 osync_client_set_incoming_queue(client, incoming);
00100 osync_queue_unref(incoming);
00101 osync_client_set_outgoing_queue(client, outgoing);
00102 osync_queue_unref(outgoing);
00103 } else {
00104
00105 incoming = osync_queue_new(pipe_path, &error);
00106 if (!incoming)
00107 goto error;
00108
00109 if (!osync_queue_create(incoming, &error))
00110 goto error;
00111
00112
00113 if (!osync_queue_connect(incoming, OSYNC_QUEUE_RECEIVER, &error))
00114 goto error;
00115
00116 osync_client_set_incoming_queue(client, incoming);
00117 osync_queue_unref(incoming);
00118 }
00119
00120 osync_client_run_and_block(client);
00121
00122 osync_client_unref(client);
00123
00124
00125 osync_trace(TRACE_EXIT, "%s", __func__);
00126 return 0;
00127
00128 error:
00129 osync_client_unref(client);
00130
00131 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error));
00132 fprintf(stderr, "Unable to initialize environment: %s\n", osync_error_print(&error));
00133 osync_error_unref(&error);
00134 return 1;
00135 }