sysclient.c

Go to the documentation of this file.
00001 /*
00002  * File Name: sysclient.c
00003  */
00004 
00005 /*
00006  * This file is part of sysd.
00007  *
00008  * sysd 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  * sysd 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) 2008 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 <glib.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 
00039 // ereader include files, between < >
00040 #include <liberipc/eripc.h>
00041 #include <liberipc/eripc_support.h>
00042 
00043 // local include files, between " "
00044 #include "log.h"
00045 
00046 
00047 //----------------------------------------------------------------------------
00048 // Type Declarations
00049 //----------------------------------------------------------------------------
00050 
00051 
00052 //----------------------------------------------------------------------------
00053 // Global Constants
00054 //----------------------------------------------------------------------------
00055 
00056 #define DBUS_APPL_NAME       "sysclient"
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 
00061 #define DBUS_SERVICE_SYSD    "com.irexnet.sysd"
00062 #define DBUS_SERVICE_CTB     "com.irexnet.ctb"
00063 #define DBUS_SERVICE_POPUPMENU "com.irexnet.popupmenu"
00064      
00065 //----------------------------------------------------------------------------
00066 // Static Variables
00067 //----------------------------------------------------------------------------
00068 
00069 static eripc_client_context_t *eripcClient = NULL;
00070 
00071 
00072 //============================================================================
00073 // Local Function Definition
00074 //============================================================================
00075 
00076 static void usage(const char *argv_0);
00077 
00078 
00079 //============================================================================
00080 // Functions Implementation
00081 //============================================================================
00082 
00083 int main(int argc, char *argv[])
00084 {
00085     if (argc <= 1)
00086     {
00087         usage(argv[0]);
00088         return 1;
00089     }
00090     
00091     eripcClient = eripc_client_context_new(
00092                     DBUS_APPL_NAME,
00093                     "1.0",
00094                     DBUS_SERVICE,
00095                     DBUS_PATH,
00096                     DBUS_INTERFACE,
00097                     NULL);
00098     
00099     if (eripcClient == NULL)
00100     {
00101         printf("Cannot connect to DBUS, make sure DISPLAY environment variable is set.\n\n");
00102         return 1;
00103     }
00104     
00105     if (strcmp(argv[1], "startTask") == 0)
00106     {
00107         if (argc == 6)
00108         {
00109             LOGPRINTF("Calling %s %s...", argv[1], argv[2]);
00110             
00111             eripc_send_varargs(eripcClient->context, 
00112                                NULL,
00113                                NULL,
00114                                ERIPC_BUS_SESSION,
00115                                DBUS_SERVICE_SYSD,
00116                                argv[1], 
00117                                ERIPC_TYPE_STRING, argv[2],
00118                                ERIPC_TYPE_STRING, argv[3],
00119                                ERIPC_TYPE_STRING, argv[4],
00120                                ERIPC_TYPE_STRING, argv[5],
00121                                ERIPC_TYPE_INVALID);
00122         }
00123         else
00124         {
00125             WARNPRINTF("Invalid args for %s", argv[1]);
00126         }
00127     }
00128     else if ((strcmp(argv[1], "menuRequestPopup") == 0)
00129           || (strcmp(argv[1], "stopTask")         == 0))
00130     {
00131         if (argc == 3)
00132         {
00133             LOGPRINTF("Calling %s %s...", argv[1], argv[2]);
00134             
00135             eripc_send_varargs(eripcClient->context,
00136                                NULL,
00137                                NULL,
00138                                ERIPC_BUS_SESSION,
00139                                DBUS_SERVICE_SYSD,
00140                                argv[1], 
00141                                ERIPC_TYPE_STRING, argv[2],
00142                                ERIPC_TYPE_INVALID);
00143         }
00144         else
00145         {
00146             WARNPRINTF("Invalid args for %s", argv[1]);
00147         }
00148     }
00149     else if (strcmp(argv[1], "gotoHome") == 0)
00150     {
00151         if (argc == 2)
00152         {
00153             LOGPRINTF("Calling %s...", argv[1]);
00154             
00155             eripc_send_varargs(eripcClient->context,
00156                                NULL,
00157                                NULL,
00158                                ERIPC_BUS_SESSION,
00159                                DBUS_SERVICE_SYSD,
00160                                "menuItemActivated", 
00161                                ERIPC_TYPE_STRING, "desktop", /* item */
00162                                ERIPC_TYPE_STRING, "general", /* group */
00163                                ERIPC_TYPE_STRING, "", /* menu */
00164                                ERIPC_TYPE_STRING, "", /* state */
00165                                ERIPC_TYPE_INVALID);
00166         }
00167         else
00168         {
00169             WARNPRINTF("Invalid args for %s", argv[1]);
00170         }
00171     }
00172     else if ((strcmp(argv[1], "sysCardUnmount") == 0)
00173           || (strcmp(argv[1], "sysShutdown")    == 0)
00174           || (strcmp(argv[1], "sysStandby")     == 0))
00175     {
00176         if (argc == 2)
00177         {
00178             LOGPRINTF("Calling %s...", argv[1]);
00179             
00180             eripc_send_varargs(eripcClient->context,
00181                                NULL,
00182                                NULL,
00183                                ERIPC_BUS_SESSION,
00184                                DBUS_SERVICE_SYSD,
00185                                argv[1], 
00186                                ERIPC_TYPE_INVALID);
00187         }
00188         else
00189         {
00190             WARNPRINTF("Invalid args for %s", argv[1]);
00191         }
00192     }
00193     else if ((strcmp(argv[1], "sysCardMount")  == 0))
00194     {
00195         if (argc == 2)
00196         {
00197             LOGPRINTF("Calling %s...", argv[1]);
00198             
00199             eripc_send_varargs(eripcClient->context,
00200                                NULL,
00201                                NULL,
00202                                ERIPC_BUS_SESSION,
00203                                DBUS_SERVICE_SYSD,
00204                                argv[1], 
00205                                ERIPC_TYPE_BOOL, TRUE,
00206                                ERIPC_TYPE_INVALID);
00207         }
00208         else
00209         {
00210             WARNPRINTF("Invalid args for %s", argv[1]);
00211         }
00212     }
00213     else if ((strcmp(argv[1], "ctbRefresh") == 0))
00214     {
00215         LOGPRINTF("Calling %s...", argv[1]);
00216         
00217         eripc_send_varargs(eripcClient->context,
00218                       NULL,
00219                       NULL,
00220                       ERIPC_BUS_SESSION,
00221                       DBUS_SERVICE_CTB,
00222                       "filesystemChanged", 
00223                       ERIPC_TYPE_INVALID);
00224     }
00225     else if ((strcmp(argv[1], "listTasks") == 0))
00226     {
00227         LOGPRINTF("Calling %s...", argv[1]);
00228         
00229         eripc_send_varargs(eripcClient->context,
00230                       NULL,
00231                       NULL,
00232                       ERIPC_BUS_SESSION,
00233                       DBUS_SERVICE_SYSD,
00234                       "testingListTasks", 
00235                       ERIPC_TYPE_INVALID);
00236     }
00237     else if ((strcmp(argv[1], "listMenu") == 0))
00238     {
00239         LOGPRINTF("Calling %s...", argv[1]);
00240         
00241         eripc_send_varargs(eripcClient->context,
00242                       NULL,
00243                       NULL,
00244                       ERIPC_BUS_SESSION,
00245                       DBUS_SERVICE_POPUPMENU,
00246                       "testingListMenuItems", 
00247                       ERIPC_TYPE_INVALID);
00248     }
00249     else
00250     {
00251         usage(argv[0]);
00252     }
00253     return 1;
00254 }
00255 
00256 
00257 static void usage(const char *argv_0)
00258 {
00259     static const char *usage_text = 
00260         "Usage:\n"
00261         "    %s <command> [<arguments>]\n"
00262         "\n"
00263         "Commands and aguments:\n"
00264         "    startTask\t- start a new task/application\n"
00265         "    \tcommand_line\tstring, full path to application with arguments\n"
00266         "    \tworking_dir\tstring, current working directory\n"
00267         "    \tlabel\tstring, text label shown under icon in popup menu\n"
00268         "    \timage\tstring, full path to icon shown in popup menu (png, 60x60 pixels)\n"
00269         "    stopTask\t- stop a running task/applciation\n"
00270         "    \tcommand_line\tstring, full path to application with arguments\n"
00271         "    listTasks\t- show lists of running tasks, windows and processes\n"
00272         "    menuRequestPopup\t- show/hide the popupmenu\n"
00273         "    \tstate\tstring, \"show\" | \"hide\" | \"toggle\"\n"
00274         "    gotoHome\t- activate ctb desktop/home\n"
00275         "    sysCardMount\t- mount the SD card(s)\n"
00276         "    sysCardUnmount\t- unmount the SD card(s)\n"
00277         "    sysShutdown\t- graciously shut down the system\n"
00278         "    sysStandby\t- enter standby mode\n"
00279         "    ctbRefresh\t- refresh ctb fileview from database\n"
00280         "    listMenu\t- show all entries in popupmenu\n"
00281         "\n";
00282  
00283     printf(usage_text, argv_0);
00284 
00285     exit(1);
00286 }
Generated by  doxygen 1.6.2-20100208