menuapitest.c File Reference

#include "config.h"
#include <glib.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <liberipc/eripc.h>
Include dependency graph for menuapitest.c:

Go to the source code of this file.

Defines

#define DBUS_SERVICE   "com.irexnet.popupmenu"

Enumerations

enum  cmd_type {
  CMD_UNKNOWN, CMD_ADD, CMD_REMOVE, CMD_SET_STATE,
  CMD_SHOW, CMD_HIDE, NUM_CMD
}
enum  prop_type {
  PROP_UNKNOWN, PROP_GROUP, PROP_STATUSITEM, PROP_MENUITEM,
  PROP_MENU, NUM_PROP
}

Functions

static const gchar * eripcErrorStr (eripc_error_t errorcode)
static void set_item_state (eripc_context_t *ctx, const char *iname, const char *pname, const char *state)
static void set_group_state (eripc_context_t *ctx, const char *pname, const char *state)
static void set_popup_state (eripc_context_t *ctx, const char *state)
static void set_statusitem_state (eripc_context_t *ctx, const char *iname, const char *state)
static void show_statusitem (eripc_context_t *ctx, const char *iname)
static void hide_statusitem (eripc_context_t *ctx, const char *iname)
static void remove_group (eripc_context_t *ctx, const char *name)
static void remove_item (eripc_context_t *ctx, const char *name, const char *parent)
static void remove_menu (eripc_context_t *ctx, const char *name)
static void show_menu (eripc_context_t *ctx, const char *name)
void usage ()
int main (int argc, char **argv)

Variables

static gboolean verbose_flag = FALSE
int activated_handler = -1
eripc_context_teripcContext = NULL

Define Documentation

#define DBUS_SERVICE   "com.irexnet.popupmenu"

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 36 of file menuapitest.c.


Enumeration Type Documentation

enum cmd_type
Enumerator:
CMD_UNKNOWN 
CMD_ADD 
CMD_REMOVE 
CMD_SET_STATE 
CMD_SHOW 
CMD_HIDE 
NUM_CMD 

Definition at line 42 of file menuapitest.c.

00043 {
00044   CMD_UNKNOWN,
00045   CMD_ADD,
00046   CMD_REMOVE,
00047   CMD_SET_STATE,
00048   CMD_SHOW,
00049   CMD_HIDE,
00050   NUM_CMD
00051 };

enum prop_type
Enumerator:
PROP_UNKNOWN 
PROP_GROUP 
PROP_STATUSITEM 
PROP_MENUITEM 
PROP_MENU 
NUM_PROP 

Definition at line 53 of file menuapitest.c.

00054 {
00055   PROP_UNKNOWN,
00056   PROP_GROUP,
00057   PROP_STATUSITEM,
00058   PROP_MENUITEM,
00059   PROP_MENU,
00060   NUM_PROP
00061 };


Function Documentation

static const gchar* eripcErrorStr ( eripc_error_t  errorcode  )  [static]

Definition at line 63 of file menuapitest.c.

References ERIPC_ERROR, ERIPC_ERROR_INVALID, ERIPC_ERROR_OOM, ERIPC_ERROR_SUCCESS, and ERIPC_ERROR_TIMEOUT.

Referenced by hide_statusitem(), remove_group(), remove_item(), remove_menu(), set_group_state(), set_item_state(), set_popup_state(), set_statusitem_state(), show_menu(), and show_statusitem().

00064 {
00065     switch (errorcode) 
00066     {
00067     case ERIPC_ERROR_SUCCESS:
00068         return "No error (ERIPC_ERROR_SUCCESS)";
00069     case ERIPC_ERROR:
00070         return "Some kind of error occurred (ERIPC_ERROR)";
00071     case ERIPC_ERROR_INVALID:
00072         return "At least one parameter is invalid (ERIPC_ERROR_INVALID)";
00073     case ERIPC_ERROR_OOM:
00074         return "Out of memory error (ERIPC_ERROR_OOM)";
00075     case ERIPC_ERROR_TIMEOUT:
00076         return "Timeout error (ERIPC_ERROR_TIMEOUT)";
00077     default:
00078         return "Unknown/Undefined";
00079     }
00080 }

Here is the caller graph for this function:

static void hide_statusitem ( eripc_context_t ctx,
const char *  iname 
) [static]

Definition at line 256 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00257 {
00258     eripc_error_t result;
00259     
00260     g_return_if_fail(iname != NULL);
00261 
00262     result = eripc_send_varargs_and_wait(ctx,
00263                                 NULL,
00264                                 ERIPC_BUS_SESSION,
00265                                 DBUS_SERVICE,
00266                                 "hideStatusItem",
00267                                 ERIPC_TYPE_STRING, iname,
00268                                 ERIPC_TYPE_INVALID);
00269 
00270     if (result != ERIPC_ERROR_SUCCESS) 
00271    {
00272         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00273     }
00274 }

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 380 of file menuapitest.c.

References CMD_HIDE, CMD_REMOVE, CMD_SET_STATE, CMD_SHOW, CMD_UNKNOWN, eripc_init(), eripc_set_timeout(), hide_statusitem(), name, PROP_GROUP, PROP_MENU, PROP_MENUITEM, PROP_STATUSITEM, PROP_UNKNOWN, remove_group(), remove_item(), remove_menu(), set_group_state(), set_item_state(), set_popup_state(), set_statusitem_state(), show_menu(), show_statusitem(), usage(), and verbose_flag.

00381 {
00382     int c;
00383     
00384     enum cmd_type command = CMD_UNKNOWN;
00385     enum prop_type property = PROP_UNKNOWN;
00386     GMainLoop *gloop = NULL;
00387     GString *iname = NULL;
00388     GString *pname = NULL;
00389     GString *state = NULL;
00390 
00391     gloop = g_main_loop_new(NULL, FALSE);
00392     eripcContext = eripc_init("menuapitest", "1.0", NULL);
00393     if (eripcContext == NULL) 
00394     {
00395        g_error("Failed to initialize IPC API\n");
00396     }
00397 
00398     eripc_set_timeout(eripcContext, 2000);
00399 
00400     while (1)
00401     {
00402        static struct option long_options[] =
00403          {
00404            /* These options set a flag. */
00405            {"verbose", no_argument,       &verbose_flag, TRUE},
00406            /* These options don't set a flag.
00407               We distinguish them by their indices. */
00408            {"remove",   no_argument,       NULL, 'r'},
00409            {"show",     no_argument,       NULL, 's'},
00410            {"hide",     no_argument,       NULL, 'h'},
00411            {"item",     required_argument, NULL, 'i'},
00412            {"group",    required_argument, NULL, 'g'},
00413            {"menu",     optional_argument, NULL, 'm'},
00414            {"newstate", required_argument, NULL, 'n'},
00415            {"statusitem",required_argument,NULL, 't'},
00416            {0, 0, 0, 0}
00417          };
00418        /* getopt_long stores the option index here. */
00419        int option_index = 0;
00420  
00421         c = getopt_long (argc, argv, "rshi:g:n:t:m::", long_options, &option_index);
00422  
00423        /* Detect the end of the options. */
00424        if (c == -1)
00425          break;
00426  
00427        switch (c)
00428          {
00429          case 0:
00430            /* If this option set a flag, do nothing else now. */
00431            if (long_options[option_index].flag != 0)
00432              break;
00433            g_print("option %s", long_options[option_index].name);
00434            if (optarg)
00435              g_print(" with arg %s", optarg);
00436            g_print("\n");
00437            break;
00438  
00439          case 'r':
00440            command = CMD_REMOVE;
00441            g_print("option -r\n");
00442            break;
00443  
00444          case 's':
00445            command = CMD_SHOW;
00446            g_print("option -s\n");
00447            break;
00448  
00449          case 'h':
00450            command = CMD_HIDE;
00451            g_print("option -h\n");
00452            break;
00453                      
00454          case 'i':
00455            if (pname != NULL)
00456            {
00457              g_print("option -i with value `%s'\n", optarg);
00458              property = PROP_MENUITEM;
00459              iname = g_string_new(optarg);
00460            }
00461            else 
00462            {
00463              g_error("option -g must be set before -i\n");
00464            }
00465            break;
00466  
00467          case 't':
00468            g_print("option -t with value `%s'\n", optarg);
00469            property = PROP_STATUSITEM;
00470            iname = g_string_new(optarg);
00471            break;
00472                      
00473          case 'g':
00474            g_print("option -g with value `%s'\n", optarg);
00475            property = PROP_GROUP;
00476            pname = g_string_new(optarg);
00477            break;
00478  
00479          case 'm':
00480            pname = g_string_new(optarg);
00481            if (optarg != NULL)
00482            {
00483                 g_print("option -m with value `%s'\n", optarg);
00484            }
00485            else
00486            {
00487                 g_print("option -m\n");
00488            }
00489                      
00490            if (property==PROP_UNKNOWN) 
00491            {
00492                property = PROP_MENU;
00493            }
00494            break;
00495  
00496          case 'n':
00497            g_print("option -n with value `%s'\n", optarg);
00498            command = CMD_SET_STATE;
00499            state = g_string_new(optarg);
00500            break;
00501  
00502          case '?':
00503            /* getopt_long already printed an error message. */
00504            usage();
00505            break;
00506  
00507          default:
00508            usage();
00509            break;
00510          }
00511     }
00512  
00513    if (verbose_flag)
00514      g_print("verbose flag is set");
00515  
00516    if (optind < argc)
00517      {
00518        g_print("unsupported options: ");
00519        while (optind < argc)
00520          g_print("%s ", argv[optind++]);
00521        g_print("\n");
00522      }
00523  
00524     switch (command)
00525     {
00526     case CMD_REMOVE:
00527       switch (property)
00528       {
00529       case PROP_MENUITEM:
00530         remove_item(eripcContext, iname->str, pname->str);
00531         break;
00532       case PROP_GROUP:
00533         remove_group(eripcContext, pname->str);
00534         break;
00535       case PROP_MENU:
00536         remove_menu(eripcContext, pname->str);
00537         break;
00538       default:
00539         break;
00540       }
00541       break;
00542         
00543     case CMD_SET_STATE:
00544       switch (property)
00545       {
00546       case PROP_STATUSITEM:
00547         set_statusitem_state(eripcContext, iname->str, state->str);
00548         break;
00549       case PROP_MENUITEM:
00550         set_item_state(eripcContext, iname->str, pname->str, state->str);
00551         break;
00552       case PROP_GROUP:
00553         set_group_state(eripcContext, pname->str, state->str);
00554         break;
00555       case PROP_MENU:
00556         set_popup_state(eripcContext, state->str);
00557         break;
00558       default:
00559         break;
00560       }
00561       break;
00562         
00563     case CMD_SHOW:
00564       switch (property)
00565       {
00566       case PROP_MENU:
00567         show_menu(eripcContext, pname->str);     
00568         break;
00569       case PROP_STATUSITEM:
00570         show_statusitem(eripcContext, iname->str);
00571         break;
00572       default:
00573         break;
00574       }
00575       break;
00576         
00577     case CMD_HIDE:
00578       switch (property)
00579       {
00580       case PROP_STATUSITEM:
00581         hide_statusitem(eripcContext, iname->str);
00582         break;
00583       default:
00584         break;
00585       }
00586       break;
00587         
00588     default:
00589       break;
00590     }
00591     
00592     eripcContext = NULL;
00593     return EXIT_SUCCESS;    
00594 }

Here is the call graph for this function:

static void remove_group ( eripc_context_t ctx,
const char *  name 
) [static]

Definition at line 277 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00278 {
00279     eripc_error_t result;
00280     
00281     g_return_if_fail(name != NULL);
00282 
00283     result = eripc_send_varargs_and_wait(ctx,
00284                                 NULL,
00285                                 ERIPC_BUS_SESSION,
00286                                 DBUS_SERVICE,
00287                                 "removeGroup",
00288                                 ERIPC_TYPE_STRING, name,
00289                                 ERIPC_TYPE_INVALID);
00290 
00291     if (result != ERIPC_ERROR_SUCCESS) 
00292    {
00293         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00294     }
00295 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void remove_item ( eripc_context_t ctx,
const char *  name,
const char *  parent 
) [static]

Definition at line 298 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00299 {
00300     eripc_error_t result;
00301     
00302     g_return_if_fail(name != NULL);
00303 
00304     result = eripc_send_varargs_and_wait(ctx,
00305                                 NULL,
00306                                 ERIPC_BUS_SESSION,
00307                                 DBUS_SERVICE,
00308                                 "removeItem",
00309                                 ERIPC_TYPE_STRING, name,
00310                                 ERIPC_TYPE_STRING, parent,
00311                                 ERIPC_TYPE_INVALID);
00312 
00313     if (result != ERIPC_ERROR_SUCCESS) 
00314    {
00315         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00316     }
00317 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void remove_menu ( eripc_context_t ctx,
const char *  name 
) [static]

Definition at line 319 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00320 {
00321     eripc_error_t result;
00322     
00323     g_return_if_fail(name != NULL);
00324     
00325     result = eripc_send_varargs_and_wait(ctx,
00326                                 NULL,
00327                                 ERIPC_BUS_SESSION,
00328                                 DBUS_SERVICE,
00329                                 "removeMenu",
00330                                 ERIPC_TYPE_STRING, name,
00331                                 ERIPC_TYPE_INVALID);
00332 
00333     if (result != ERIPC_ERROR_SUCCESS) 
00334    {
00335         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00336     }
00337 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_group_state ( eripc_context_t ctx,
const char *  pname,
const char *  state 
) [static]

Definition at line 169 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00170 {
00171     eripc_error_t result;
00172     
00173     g_return_if_fail(pname != NULL);
00174     g_return_if_fail(state != NULL);
00175     
00176     result = eripc_send_varargs_and_wait(ctx,
00177                                 NULL,
00178                                 ERIPC_BUS_SESSION,
00179                                 DBUS_SERVICE,
00180                                 "setGroupState",
00181                                 ERIPC_TYPE_STRING, pname,
00182                                 ERIPC_TYPE_STRING, state,
00183                                 ERIPC_TYPE_INVALID);
00184 
00185     if (result != ERIPC_ERROR_SUCCESS) 
00186    {
00187         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00188     }
00189 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_item_state ( eripc_context_t ctx,
const char *  iname,
const char *  pname,
const char *  state 
) [static]

Definition at line 145 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00146 {
00147     eripc_error_t result;
00148     
00149     g_return_if_fail(pname != NULL);
00150     g_return_if_fail(state != NULL);
00151     
00152     result = eripc_send_varargs_and_wait(ctx,
00153                                 NULL,
00154                                 ERIPC_BUS_SESSION,
00155                                 DBUS_SERVICE,
00156                                 "setItemState",
00157                                 ERIPC_TYPE_STRING, iname,
00158                                 ERIPC_TYPE_STRING, pname,
00159                                 ERIPC_TYPE_STRING, state,
00160                                 ERIPC_TYPE_INVALID);
00161 
00162     if (result != ERIPC_ERROR_SUCCESS) 
00163    {
00164         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00165     }
00166 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_popup_state ( eripc_context_t ctx,
const char *  state 
) [static]

Definition at line 191 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00192 {
00193     eripc_error_t result;
00194     
00195     g_return_if_fail(state != NULL);
00196   
00197     result = eripc_send_varargs_and_wait(ctx,
00198                                 NULL,
00199                                 ERIPC_BUS_SESSION,
00200                                 DBUS_SERVICE,
00201                                 "setPopupState",
00202                                 ERIPC_TYPE_STRING, state,
00203                                 ERIPC_TYPE_INVALID);
00204 
00205     if (result != ERIPC_ERROR_SUCCESS) 
00206    {
00207         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00208     }
00209 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_statusitem_state ( eripc_context_t ctx,
const char *  iname,
const char *  state 
) [static]

Definition at line 212 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00213 {
00214     eripc_error_t result;
00215     
00216     g_return_if_fail(iname != NULL);
00217     g_return_if_fail(state != NULL);
00218 
00219     result = eripc_send_varargs_and_wait(ctx,
00220                                 NULL,
00221                                 ERIPC_BUS_SESSION,
00222                                 DBUS_SERVICE,
00223                                 "setStatusItemState",
00224                                 ERIPC_TYPE_STRING, iname,
00225                                 ERIPC_TYPE_STRING, state,
00226                                 ERIPC_TYPE_INVALID);
00227 
00228     if (result != ERIPC_ERROR_SUCCESS) 
00229    {
00230         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00231     }
00232 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void show_menu ( eripc_context_t ctx,
const char *  name 
) [static]

Definition at line 340 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00341 {
00342     eripc_error_t result;
00343     
00344     g_return_if_fail(name != NULL);
00345         
00346     result = eripc_send_varargs_and_wait(ctx,
00347                                 NULL,
00348                                 ERIPC_BUS_SESSION,
00349                                 DBUS_SERVICE,
00350                                 "showMenu",
00351                                 ERIPC_TYPE_STRING, name,
00352                                 ERIPC_TYPE_INVALID);
00353 
00354     if (result != ERIPC_ERROR_SUCCESS) 
00355     {
00356         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00357     }
00358 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void show_statusitem ( eripc_context_t ctx,
const char *  iname 
) [static]

Definition at line 235 of file menuapitest.c.

References DBUS_SERVICE, ERIPC_BUS_SESSION, ERIPC_ERROR_SUCCESS, eripc_send_varargs_and_wait(), ERIPC_TYPE_INVALID, ERIPC_TYPE_STRING, and eripcErrorStr().

Referenced by main().

00236 {
00237     eripc_error_t result;
00238     
00239     g_return_if_fail(iname != NULL);
00240     
00241     result = eripc_send_varargs_and_wait(ctx,
00242                                 NULL,
00243                                 ERIPC_BUS_SESSION,
00244                                 DBUS_SERVICE,
00245                                 "showStatusItem",
00246                                 ERIPC_TYPE_STRING, iname,
00247                                 ERIPC_TYPE_INVALID);
00248 
00249     if (result != ERIPC_ERROR_SUCCESS) 
00250    {
00251         g_error("Error launching the RPC (%s)\n", eripcErrorStr(result));
00252     }
00253 }

Here is the call graph for this function:

Here is the caller graph for this function:

void usage (  ) 

Definition at line 360 of file menuapitest.c.

00361 {
00362     g_print("Usage: %s -r -s -n newstate -i item -g group -m menu -t statusitem\n", "menuapitest");
00363     g_print("\t-r --remove\t\tRemove command, followed by item, group or menu\n");
00364     g_print("\t-s --show\t\tShow command, followed by menu\n");
00365     g_print("\t-n --newstate <newstate>\tSet new state to:\n");
00366     g_print("\t\t\titem:\tNORMAL, SELECTED, DISABLED\n");
00367     g_print("\t\t\tgroup:\tNORMAL, DISABLED\n");
00368     g_print("\t\t\tmenu:\tSHOW, HIDE, TOGGLE\n");
00369     g_print("\t\t\tstatus:\tname of status\n");
00370     g_print("\t-i --item=<item>\tItem to operate command (group must be specified first)\n");
00371     g_print("\t-g --group=<group>\tGroup to operate command\n");
00372     g_print("\t-m --menu[=<menu>]\tMenu to operate command (menu name not required for 'newstate')\n");
00373     g_print("\t-t --statusitem=<statusitem>\tStatus item to operate command\n");
00374     g_print("Example: %s --show --menu=uds_menu_reading\n", "menuapitest");
00375     g_print("Example: %s --newstate=SELECTED --group=system --item=rotate_screen\n", "menuapitest");
00376     g_print("Example: %s --newstate=cha040 --statusitem=battery\n", "menuapitest");
00377     g_print("Example: %s --newstate=TOGGLE --menu\n", "menuapitest");
00378 }


Variable Documentation

Definition at line 39 of file menuapitest.c.

Referenced by install_activation_handler(), and term_handler().

Definition at line 40 of file menuapitest.c.

gboolean verbose_flag = FALSE [static]

Definition at line 38 of file menuapitest.c.

Referenced by main().

Generated by  doxygen 1.6.2-20100208