index_ipc.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "config.h"
00032
00033
00034 #include <stdlib.h>
00035 #include <unistd.h>
00036
00037
00038 #include <liberipc/eripc.h>
00039 #include <liberipc/eripc_support.h>
00040 #include <liberutils/er_error.h>
00041
00042
00043 #include "ctb_log.h"
00044 #include "index_ipc.h"
00045 #include "index.h"
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #define DBUS_APPL_NAME "index"
00057 #define DBUS_SERVICE "com.irexnet." DBUS_APPL_NAME
00058 #define DBUS_PATH "/com/irexnet/" DBUS_APPL_NAME
00059 #define DBUS_INTERFACE "com.irexnet." DBUS_APPL_NAME
00060 #define DBUS_SERVICE_UDS "com.irexnet.uds"
00061
00062 #define DBUS_STORE_METADATA_TIMEOUT 25000
00063
00064
00065
00066
00067
00068 static eripc_client_context_t *eripcClient = NULL;
00069
00070
00071
00072
00073
00074 static void on_storemetadata_ready( eripc_context_t *context,
00075 const eripc_event_info_t *info,
00076 void *user_data );
00077
00078
00079 static eripc_callback_function_t service_functions[] = {
00080 { on_storemetadata_ready, "storeMetadataReady", NULL, 0},
00081 { NULL, NULL, NULL ,0 }
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 void ipc_set_services ()
00096 {
00097 eripcClient = eripc_client_context_new(
00098 DBUS_APPL_NAME,
00099 "1.0",
00100 DBUS_SERVICE,
00101 DBUS_PATH,
00102 DBUS_INTERFACE,
00103 service_functions);
00104 }
00105
00106
00107
00108 void ipc_unset_services (void)
00109 {
00110 eripc_client_context_free(eripcClient, service_functions);
00111 }
00112
00113
00114
00115
00116
00117 gboolean ipc_send_store_metadata(const char *dir, const char *document)
00118 {
00119 LOGPRINTF("entry");
00120
00121 char* fullpath = (char *)calloc(strlen(dir) + strlen(document) + 2, sizeof(char));
00122 strcat(fullpath, dir);
00123 strcat(fullpath, "/");
00124 strcat(fullpath, document);
00125
00126 eripc_error_t retval;
00127
00128 g_return_val_if_fail(document != NULL, FALSE);
00129
00130 int status = (int)eripc_set_timeout(eripcClient->context, DBUS_STORE_METADATA_TIMEOUT);
00131 if (status != 0)
00132 {
00133 ERRORPRINTF("Could not set timeout, status = [%d]", status);
00134 }
00135
00136 retval = eripc_send_string_and_wait(eripcClient->context,
00137 NULL,
00138 ERIPC_BUS_SESSION,
00139 DBUS_SERVICE_UDS,
00140 "storeMetadata",
00141 fullpath);
00142
00143
00144
00145 free(fullpath);
00146
00147 if (retval != ERIPC_ERROR_SUCCESS)
00148 {
00149 ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00150 return FALSE;
00151 }
00152
00153 return TRUE;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 static void on_storemetadata_ready ( eripc_context_t *context,
00166 const eripc_event_info_t *info,
00167 void *user_data )
00168 {
00169 LOGPRINTF("entry");
00170
00171 store_metadata_ready();
00172 }
00173