00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <unistd.h>
00027 #include <netinet/in.h>
00028
00029 #include "liberdm/erdm.h"
00030
00031
00032
00033 #define ERDMG_LOGGING_ON 1
00034 #define ERDMG_WARNING_ON 1
00035 #define ERDMG_ERROR_ON 1
00036
00037 #if (ERDMG_LOGGING_ON)
00038 #define ERDMG_LOGPRINTF(x, args...) fprintf(stderr, "(L)" __FILE__ ":%d,%s() " x "\n", __LINE__, __func__ , ##args)
00039 #else
00040 #define ERDMG_LOGPRINTF(x, args...) do {} while (0)
00041 #endif
00042
00043 #if (ERDMG_WARNING_ON)
00044 #define ERDMG_WARNPRINTF(x, args...) fprintf(stderr, "(W)" __FILE__ ":%d,%s() " x "\n", __LINE__, __func__ , ##args)
00045 #else
00046 #define ERDMG_WARNPRINTF(x, args...) do {} while (0)
00047 #endif
00048
00049 #if (ERDMG_ERROR_ON)
00050 #define ERDMG_ERRORPRINTF(x, args...) fprintf(stderr, "(E)" __FILE__ ":%d,%s() " x "\n", __LINE__, __func__ , ##args)
00051 #else
00052 #define ERDMG_ERRORPRINTF(x, args...) do {} while (0)
00053 #endif
00054
00055
00056 void displayHelp()
00057 {
00058 printf("Usage: displayMgrClient -<option> <argument>\n");
00059 printf(" no arguments : send messages to local loop\n");
00060 printf(" -d <dotted decimal ip address> : send messages to ip address\n");
00061 printf(" -h : display this message\n");
00062 printf(" -p : test of partial update\n");
00063 printf(" -r <seconds> : repeat a full update every <seconds>\n");
00064 printf(" -t : update toolbar area\n");
00065 }
00066
00067 int main(int argc, char **argv)
00068 {
00069 char szDestination[INET_ADDRSTRLEN];
00070 char szLocalLoop[] = "127.0.0.1";
00071 int fUserAddress = 0;
00072 int fRepeat = 0;
00073 int fTest = 0;
00074 int fToolbarUpdate = 0;
00075 int nArg = 1;
00076 int ret;
00077 int nRepeatAfterSeconds = 0;
00078
00079
00080 fUserAddress = 0;
00081
00082
00083
00084
00085
00086 while (nArg < argc)
00087 {
00088 if (argv[nArg][0] == '-')
00089 {
00090 switch (argv[nArg][1])
00091 {
00092 case 'h':
00093 displayHelp();
00094 return 0;
00095 break;
00096
00097 case 'd':
00098 fUserAddress = 1;
00099
00100 if (++nArg >= argc)
00101 {
00102
00103 ERDMG_ERRORPRINTF("Supply a dotted decimal ip address after option -d");
00104 displayHelp();
00105 return -1;
00106 }
00107 else
00108 {
00109 strncpy(szDestination, argv[nArg], INET_ADDRSTRLEN);
00110 nArg++;
00111 }
00112 break;
00113
00114 case 'r':
00115 fRepeat = 1;
00116
00117 if (++nArg >= argc)
00118 {
00119
00120 ERDMG_ERRORPRINTF("Supply seconds after option -r");
00121 displayHelp();
00122 return -1;
00123 }
00124 else
00125 {
00126 char *pDummy;
00127 long lSeconds;
00128
00129 lSeconds = strtol(argv[nArg], &pDummy, 10);
00130 if (pDummy == argv[nArg])
00131 {
00132
00133 ERDMG_ERRORPRINTF("Please specify a positive integer larger than 1 after -r option.");
00134 displayHelp();
00135 return -1;
00136 }
00137 else if (lSeconds < 1)
00138 {
00139
00140 ERDMG_ERRORPRINTF("Please specify a positive integer larger than 0 after -r option.");
00141 displayHelp();
00142 return -1;
00143 }
00144 else
00145 {
00146 nRepeatAfterSeconds = (int) lSeconds;
00147 }
00148 nArg++;
00149 }
00150 break;
00151
00152 case 'p':
00153 fTest = 1;
00154 nArg++;
00155 break;
00156
00157 case 't':
00158 fToolbarUpdate = 1;
00159 nArg++;
00160 break;
00161
00162 default:
00163 ERDMG_ERRORPRINTF("Option %s not known.", argv[nArg]);
00164 displayHelp();
00165 return -1;
00166 }
00167 }
00168 else
00169 {
00170 ERDMG_ERRORPRINTF("Argument supplied not proceded by option.");
00171 displayHelp();
00172 return -1;
00173 }
00174 }
00175
00176 if (fUserAddress == 1)
00177 {
00178 ERDMG_WARNPRINTF("Server address %s", szDestination);
00179 }
00180 else
00181 {
00182 strncpy(szDestination, szLocalLoop, INET_ADDRSTRLEN);
00183 ERDMG_WARNPRINTF("Server address %s", szDestination);
00184 }
00185
00186 ret = dmMessageInit(szDestination);
00187 if (ret != 0)
00188 {
00189 ERDMG_ERRORPRINTF("Failed to initialize messaging.");
00190 return -1;
00191 }
00192
00193 if (fTest == 1 || fToolbarUpdate == 1)
00194 {
00195 if (fTest == 1)
00196 {
00197
00198 dmDisplayPartial(dmCmdPriorNormal, dmQFull, 100, 100, 300, 300);
00199 sleep(4);
00200 dmDisplayPartial(dmCmdPriorNormal, dmQFull, 500, 700, 700, 900);
00201 sleep(4);
00202 }
00203 if (fToolbarUpdate == 1)
00204 {
00205
00206 dmDisplayPartial(dmCmdPriorNormal, dmQFull, 4, 996, 700, 1020);
00207 sleep(4);
00208 }
00209 }
00210 else
00211 {
00212 dmDisplay(dmCmdPriorNormal, dmQFull);
00213 }
00214
00215 if (fRepeat == 1)
00216 {
00217 while (1)
00218 {
00219 dmDisplay(dmCmdPriorUrgent, dmQTyping);
00220 sleep(nRepeatAfterSeconds);
00221 }
00222 }
00223
00224 return 0;
00225 }