#include "config.h"#include <glib.h>#include <gtk/gtk.h>#include <signal.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h>#include <liberipc/eripc.h>#include <liberipc/eripc_support.h>#include "log.h"
Go to the source code of this file.
| Defines | |
| #define | LOGGING_ON 1 | 
| #define | DBUS_APPL_NAME "bert" | 
| #define | DBUS_SERVICE "com.irexnet." DBUS_APPL_NAME | 
| #define | DBUS_PATH "/com/irexnet/" DBUS_APPL_NAME | 
| #define | DBUS_INTERFACE "com.irexnet." DBUS_APPL_NAME | 
| #define | DBUS_SERVICE_ERNIE "com.irexnet.ernie" | 
| #define | MAXCOUNT 100 | 
| #define | DELAY_MS 100 | 
| Functions | |
| static void | on_ping (eripc_context_t *context, const eripc_event_info_t *info, void *user_data) | 
| static void | on_pong (eripc_context_t *context, const eripc_event_info_t *info, gpointer data) | 
| gboolean | ipc_set_services () | 
| Setup IPC connection and register API functions. | |
| void | ipc_unset_services () | 
| Unregister API functions. | |
| void | ipc_send_ping (void *callback_handler, void *callback_data) | 
| static gboolean | on_second (gpointer data) | 
| int | main (int argc, char *argv[]) | 
| Variables | |
| int | activated_handler = -1 | 
| static eripc_client_context_t * | eripcClient = NULL | 
| static eripc_callback_function_t | service_functions [] | 
| #define DBUS_SERVICE_ERNIE "com.irexnet.ernie" | 
Definition at line 33 of file bert.c.
Referenced by ipc_send_ping().
| #define LOGGING_ON 1 | 
| #define MAXCOUNT 100 | 
Definition at line 35 of file bert.c.
Referenced by on_second().
| void ipc_send_ping | ( | void * | callback_handler, | |
| void * | callback_data | |||
| ) | 
Definition at line 71 of file bert.c.
References eripc_client_context_t::context, DBUS_SERVICE_ERNIE, ERIPC_BUS_SESSION, eripc_error_string(), ERIPC_ERROR_SUCCESS, eripc_send_varargs(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, ERRORPRINTF, and LOGPRINTF.
Referenced by on_second().
00073 { 00074 eripc_error_t retval; 00075 00076 retval = eripc_send_varargs(eripcClient->context, 00077 callback_handler, 00078 callback_data, 00079 ERIPC_BUS_SESSION, 00080 DBUS_SERVICE_ERNIE, 00081 "callernie", 00082 ERIPC_TYPE_STRING, "greets from bert", 00083 ERIPC_TYPE_INVALID); 00084 00085 if (retval != ERIPC_ERROR_SUCCESS) 00086 { 00087 ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval)); 00088 return; 00089 } 00090 00091 LOGPRINTF("Sent ping"); 00092 }


| gboolean ipc_set_services | ( | ) | 
Setup IPC connection and register API functions.
File Name : index_ipc.h
Description: The dbus-based eripc functions Copyright (C) 2009 IREX Technologies B.V. All rights reserved.---------------------------------------------------------------------------
Name : ipc_set_services
| None | 
--------------------------------------------------------------------------
Definition at line 51 of file bert.c.
References DBUS_APPL_NAME, DBUS_INTERFACE, DBUS_PATH, DBUS_SERVICE, and eripc_client_context_new().
00052 { 00053 eripcClient = eripc_client_context_new( 00054 DBUS_APPL_NAME, 00055 "1.0", 00056 DBUS_SERVICE, 00057 DBUS_PATH, 00058 DBUS_INTERFACE, 00059 service_functions); 00060 00061 return TRUE; 00062 }

| void ipc_unset_services | ( | void | ) | 
Unregister API functions.
---------------------------------------------------------------------------
Name : ipc_unset_services
| -- | 
--------------------------------------------------------------------------
Definition at line 65 of file bert.c.
References eripc_client_context_free().
00066 { 00067 eripc_client_context_free(eripcClient, service_functions); 00068 }

| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) | 
Definition at line 140 of file bert.c.
References ipc_set_services(), ipc_unset_services(), LOGPRINTF, and on_second().
00141 { 00142 // init gdk (for windowing) 00143 g_type_init(); 00144 gtk_init(&argc, &argv); 00145 00146 LOGPRINTF("Starting..."); 00147 00148 // prepare IPC, system (micro) and display 00149 ipc_set_services(); 00150 00151 LOGPRINTF("Running..."); 00152 00153 gint32 interval = g_random_int_range(100, 200); 00154 g_timeout_add(interval, on_second, NULL); 00155 00156 // run the main loop 00157 LOGPRINTF("before gtk_main"); 00158 gtk_main(); 00159 LOGPRINTF("after gtk_main"); 00160 00161 ipc_unset_services(); 00162 00163 LOGPRINTF("...Exit"); 00164 00165 return 0; 00166 }

| static void on_ping | ( | eripc_context_t * | context, | |
| const eripc_event_info_t * | info, | |||
| void * | user_data | |||
| ) |  [static] | 
Definition at line 110 of file bert.c.
References eripc_reply_bool(), LOGPRINTF, and eripc_event_info_t::message_id.
00113 { 00114 gint32 wait = g_random_int_range(1000, 100*1000); 00115 00116 LOGPRINTF("Ping from ERNIE, return Pong in [%d] ms", wait/1000); 00117 g_usleep(wait); 00118 00119 eripc_reply_bool(context, info->message_id, TRUE); 00120 }

| static void on_pong | ( | eripc_context_t * | context, | |
| const eripc_event_info_t * | info, | |||
| gpointer | data | |||
| ) |  [static] | 
Definition at line 95 of file bert.c.
References ERIPC_EVENT_REPLY, eripc_event_info_t::event_type, LOGPRINTF, and WARNPRINTF.
Referenced by on_second().
00098 { 00099 if (info->event_type != ERIPC_EVENT_REPLY) 00100 { 00101 WARNPRINTF("invalid event: %d", info->event_type); 00102 } 00103 else 00104 { 00105 LOGPRINTF("Pong from ERNIE [%d]", (gint) data); 00106 } 00107 }

| static gboolean on_second | ( | gpointer | data | ) |  [static] | 
Definition at line 123 of file bert.c.
References ipc_send_ping(), MAXCOUNT, and on_pong().
Referenced by main().
00124 { 00125 static gint count = 0; 00126 00127 ipc_send_ping(on_pong, (gpointer)count++); 00128 00129 if (count>MAXCOUNT) 00130 { 00131 gtk_main_quit(); 00132 // don't call again 00133 return FALSE; 00134 } 00135 00136 return TRUE; 00137 }


| int activated_handler = -1 | 
| eripc_client_context_t* eripcClient = NULL  [static] | 
| eripc_callback_function_t service_functions[]  [static] | 
 1.6.2-20100208
 1.6.2-20100208