index_ipc.c

Go to the documentation of this file.
00001 /*
00002  * File Name: index_ipc.c
00003  */
00004 
00005 /*
00006  * This file is part of ctb.
00007  *
00008  * ctb is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * ctb is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2009 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 #include "config.h"
00032 
00033 // system include files, between < >
00034 #include <stdlib.h>
00035 #include <unistd.h>
00036 
00037 // ereader include files, between < >
00038 #include <liberipc/eripc.h>
00039 #include <liberipc/eripc_support.h>
00040 #include <liberutils/er_error.h>
00041 
00042 // local include files, between " "
00043 #include "ctb_log.h"
00044 #include "index_ipc.h"
00045 #include "index.h"
00046 
00047 //----------------------------------------------------------------------------
00048 // Type Declarations
00049 //----------------------------------------------------------------------------
00050 
00051 //----------------------------------------------------------------------------
00052 // Constants
00053 //----------------------------------------------------------------------------
00054 
00055 // IPC content browser
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 // Static Variables
00066 //----------------------------------------------------------------------------
00067 
00068 static eripc_client_context_t *eripcClient = NULL;
00069 
00070 //============================================================================
00071 // Local Function Definitions
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 // Exported DBUS API list
00079 static eripc_callback_function_t service_functions[] = {
00080     { on_storemetadata_ready, "storeMetadataReady", NULL, 0},
00081     { NULL, NULL, NULL ,0 }  // end of list
00082 };
00083 
00084 
00085 //============================================================================
00086 // Functions Implementation
00087 //============================================================================
00088 
00089 
00090 //----------------------------------------------------------------------------
00091 // Generic
00092 //----------------------------------------------------------------------------
00093 
00094 // initialise
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 // un-initialise
00108 void ipc_unset_services (void)
00109 {
00110     eripc_client_context_free(eripcClient, service_functions);
00111 }
00112 
00113 //----------------------------------------------------------------------------
00114 // Indexer
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     // Fullpath can be freed here because send_string_and_wait only returns
00144     // after executing (and it makes a copy of it anyway) [MDB]
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 // Local Function Implementation
00159 //============================================================================
00160 
00161 //----------------------------------------------------------------------------
00162 // Signal/message handlers
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 
Generated by  doxygen 1.6.2-20100208