sic_launch.c

Go to the documentation of this file.
00001 
00009 /***************************************************************************** 
00010  *                              Dependencies                                 * 
00011  *****************************************************************************/
00012 
00013 #include "sic_launch.h"
00014 
00015 #include <stdio.h>
00016 #include <fcntl.h>
00017 #ifndef WIN32
00018 #include <stdlib.h>
00019 #include <unistd.h>
00020 #include <strings.h>
00021 #else
00022 #include "win32.h"
00023 #include "keyboard.h"
00024 #include "xinput.h"
00025 #include "win-dialogs.h"
00026 #endif
00027 #include "getcar.h"
00028 #include "sic_comm.h"
00029 #include "sic_error.h"
00030 #include "sic_util.h"
00031 
00032 /***************************************************************************** 
00033  *                             Function bodies                               * 
00034  *****************************************************************************/
00035 
00036 static int start_gtv_xwindow( void *data)
00037 {
00038     int i;
00039     char **argv;
00040 
00041     argv = sic_get_static_argv( );
00042     i = 0;
00043     sprintf( argv[i++], "%s", "gtv_xwindow");
00044 #ifdef cygwin
00045     strcat( argv[i - 1], ".exe");
00046 #endif
00047     sprintf( argv[i++], "%d", sic_get_comm_id( ));
00048     argv[i++] = NULL;
00049 
00050     if (sic_execvp( argv) == -1) {
00051         sic_perror( "sic_execvp");
00052         return -1;
00053     }
00054 
00055     return 0;
00056 }
00057 
00063 task_t launch_gtv_xwindow( )
00064 {
00065     static task_t gtv_xwindow_pid = SIC_TASK_NULL;
00066 
00067     if (gtv_xwindow_pid != SIC_TASK_NULL)
00068         return SIC_TASK_NULL;
00069 
00070     gtv_xwindow_pid = sic_launch( start_gtv_xwindow, NULL);
00071 
00072     return gtv_xwindow_pid;
00073 }
00074 
00075 static int start_xinput( void *data)
00076 {
00077 #ifndef WIN32
00078     char **argv;
00079     char *widgets;
00080     char *ext = "_";
00081     int i;
00082 
00083     widgets = sic_s_get_translation( "GAG_WIDGETS");
00084     if (strcasecmp( widgets, "XML") == 0)
00085         ext = "_xml_";
00086     else if (strcasecmp( widgets, "MOTIF") == 0)
00087         ext = "_";
00088     else if (strcasecmp( widgets, "XFORMS") == 0)
00089         ext = "_xf_";
00090 
00091     /* child initialize Motif and wait for user's actions */
00092     argv = sic_get_static_argv( );
00093     i = 0;
00094     sprintf( argv[i++], "%s%s%s", "sic", ext, "xinput");
00095 #ifdef cygwin
00096     strcat( argv[i - 1], ".exe");
00097 #endif
00098     sprintf( argv[i++], "%d", sic_get_comm_id( ));
00099     argv[i++] = NULL;
00100 
00101     if (sic_execvp( argv) == -1) {
00102         sic_perror( "sic_execvp");
00103         return -1;
00104     }
00105 #else /* WIN32 */
00106     return run_xinput( 0, NULL);
00107 #endif /* WIN32 */
00108     return 0;
00109 }
00110 
00111 task_t launch_xinput( )
00112 {
00113     return sic_launch( start_xinput, NULL);
00114 }
00115 
00116 typedef struct {
00117     unsigned long win_graph;
00118     unsigned long cmap;
00119     int *pix_colors;
00120     int ncells;
00121     int *named_colors;
00122     int *pencil_colors;
00123     int ncells_pen;
00124 } gtv_motif_args_t;
00125 
00126 static int start_gtv_motif( void *data)
00127 {
00128     int i;
00129     char colorcells[129][2];
00130     char namedcells[9][2];
00131     char pencells[17][2];
00132     int debugMode = 0;          /* test for debug */
00133     char **argv;
00134     char *widgets;
00135     char *ext;
00136     gtv_motif_args_t *args = data;
00137 
00138     if (getenv( "DEBUG_LAUNCH_GTV_MOTIF") != 0)
00139         debugMode = 1;
00140 
00141     for (i = 0; i < args->ncells; i++) {
00142         sprintf( colorcells[i], "%02X", (unsigned char)args->pix_colors[i]);
00143         /* if (debugMode)   printf( "pix_colors[%d]= %s\n",i, colorcells[i]); */
00144     }
00145     colorcells[args->ncells][0] = (unsigned char)0;
00146 
00147     for (i = 0; i < 8; i++) {
00148         sprintf( namedcells[i], "%02X", (unsigned char)args->named_colors[i]);
00149         /* if (debugMode)   printf( "named_colors[%d]= %s\n", i, namedcells[i]); */
00150     }
00151     namedcells[8][0] = (unsigned char)0;
00152 
00153     for (i = 0; i < args->ncells_pen; i++) {
00154         sprintf( pencells[i], "%02X", (unsigned char)args->pencil_colors[i]);
00155         /* if (debugMode)   printf( "fill_colors[%d]= %s\n", i, pencells[i]); */
00156     }
00157     pencells[args->ncells_pen][0] = (unsigned char)0;
00158 
00159     widgets = sic_s_get_translation( "GAG_WIDGETS");
00160     if (strcasecmp( widgets, "MOTIF") == 0)
00161         ext = "_";
00162     else if (strcasecmp( widgets, "XFORMS") == 0)
00163         ext = "_xf_";
00164     else
00165         exit( 1);
00166 
00167     /* child initialize Motif and wait for user's actions */
00168     argv = sic_get_static_argv( );
00169     i = 0;
00170     sprintf( argv[i++], "%s%s%s", "gtv", ext, "motif");
00171 #ifdef cygwin
00172     strcat( argv[i - 1], ".exe");
00173 #endif
00174     sprintf( argv[i++], "%d", sic_get_comm_id( ));
00175     sprintf( argv[i++], "%lu", args->cmap);
00176     sprintf( argv[i++], "%lu", args->win_graph);
00177     sprintf( argv[i++], sic_s_get_translation( "LUT_DIR:"));
00178     sprintf( argv[i++], sic_s_get_translation( "GAG_TMP:"));
00179     sprintf( argv[i++], "%s", (char *)namedcells);
00180     sprintf( argv[i++], "%d", args->ncells_pen);
00181     sprintf( argv[i++], "%s", (char *)pencells);
00182     sprintf( argv[i++], "%d", args->ncells);
00183     sprintf( argv[i++], "%s", (char *)colorcells);
00184     argv[i++] = NULL;
00185 
00186     if (debugMode) {
00187         printf( "namedcells: %s\n", (char *)namedcells);
00188         printf( "pencells: %s\n", (char *)pencells);
00189         printf( "colorcells: %s\n", (char *)colorcells);
00190     }
00191 
00192     if (sic_execvp( argv) == -1) {
00193         sic_perror( "sic_execvp");
00194         return -1;
00195     }
00196 
00197     return 0;
00198 }
00199 
00200 task_t launch_gtv_motif( unsigned long win_graph, unsigned long cmap, int *pix_colors
00201                      , int ncells, int *named_colors, int *pencil_colors
00202                      , int ncells_pen)
00203 {
00204     static gtv_motif_args_t args;
00205     static task_t gtv_motif_pid = SIC_TASK_NULL;
00206 
00207     if (cmap == 0) {
00208 #ifndef WIN32
00209         kill( gtv_motif_pid, SIGUSR2);
00210 #endif
00211     } else {
00212         if (gtv_motif_pid != SIC_TASK_NULL) {
00213             sic_terminate( gtv_motif_pid);
00214         }
00215 
00216         args.win_graph = win_graph;
00217         args.cmap = cmap;
00218         args.pix_colors = pix_colors;
00219         args.ncells = ncells;
00220         args.named_colors = named_colors;
00221         args.pencil_colors = pencil_colors;
00222         args.ncells_pen = ncells_pen;
00223 
00224         gtv_motif_pid = sic_launch( start_gtv_motif, &args);
00225     }
00226 
00227     return gtv_motif_pid;
00228 }
00229 
00230 /* Create the detached X-Window process */
00231 static int start_xmenu( void *data)
00232 {
00233     const char *temporary_file = data;
00234 #ifndef WIN32
00235     int i;
00236     char **argv;
00237     char *widgets;
00238     char *ext = "_";
00239 
00240     widgets = sic_s_get_translation( "GAG_WIDGETS");
00241     if (strcasecmp( widgets, "XML") == 0)
00242         ext = "_xml_";
00243     else if (strcasecmp( widgets, "MOTIF") == 0)
00244         ext = "_";
00245     else if (strcasecmp( widgets, "XFORMS") == 0)
00246         ext = "_xf_";
00247 
00248     /* child initialize panel server and wait for user's actions */
00249     argv = sic_get_static_argv( );
00250     i = 0;
00251     sprintf( argv[i++], "%s%s%s", "sic", ext, "xmenu");
00252 #ifdef cygwin
00253     strcat( argv[i - 1], ".exe");
00254 #endif
00255     sprintf( argv[i++], "%d", sic_get_comm_id( ));
00256     sprintf( argv[i++], "%s", temporary_file);
00257     argv[i++] = NULL;
00258 
00259     if (sic_execvp( argv) == -1) {
00260         sic_perror( "sic_execvp");
00261         return -1;
00262     }
00263 #else /* WIN32 */
00264     MenuFunc( temporary_file);
00265 #endif /* WIN32 */
00266 
00267     return 0;
00268 }
00269 
00273 task_t launch_xmenu( const char *temporary_file)
00274 {
00275     static task_t xmenu_pid = SIC_TASK_NULL;
00276 
00277     xmenu_pid = sic_launch( start_xmenu, (void *)temporary_file);
00278 
00279     return xmenu_pid;
00280 }
00281 
00282 static int start_keyboard( void *data)
00283 {
00284 #ifndef WIN32
00285     char **argv;
00286     char *widgets;
00287     char *ext;
00288     int i;
00289 
00290     widgets = sic_s_get_translation( "GAG_WIDGETS");
00291     if (strcasecmp( widgets, "XML") == 0)
00292         ext = "_xml_";
00293     else
00294         ext = "_";
00295 
00296     /* child initialize pseudo-keyboard catchall & wait for user's actions */
00297     argv = sic_get_static_argv( );
00298     i = 0;
00299     sprintf( argv[i++], "%s%s%s", "sic", ext, "keyboard");
00300 #ifdef cygwin
00301     strcat( argv[i - 1], ".exe");
00302 #endif
00303     sprintf( argv[i++], "%d", sic_get_comm_id( ));
00304     argv[i++] = NULL;
00305 
00306     if (sic_execvp( argv) == -1) {
00307         sic_perror( "sic_execvp");
00308         return -1;
00309     }
00310 
00311     return 0;
00312 #else
00313     return run_keyboard( );
00314 #endif
00315 }
00316 
00317 task_t launch_keyboard( )
00318 {
00319     static task_t keyboard_pid = SIC_TASK_NULL;
00320 
00321     keyboard_pid = sic_launch( start_keyboard, NULL);
00322 
00323     return keyboard_pid;
00324 }
00325 
00326 void run_xremote( )
00327 {
00328     int i;
00329     char **argv = sic_get_static_argv( );
00330 
00331     i = 0;
00332     sprintf( argv[i++], "sic_xremote");
00333 #ifdef cygwin
00334     strcat( argv[i - 1], ".exe");
00335 #endif
00336     sprintf( argv[i++], "%d", sic_get_comm_id( ));
00337     argv[i++] = NULL;
00338 
00339     if (sic_execvp( argv) == -1) {  /* never returns */
00340         sic_perror( "sic_execvp");
00341     }
00342 }
00343 

Generated on Tue Mar 13 15:15:40 2007 for SIC by  doxygen 1.5.1