IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7938


Ignore:
Timestamp:
Jul 19, 2006, 10:26:59 AM (20 years ago)
Author:
eugene
Message:

unified the client/standalone command functions

Location:
trunk/Ohana/src/opihi
Files:
1 added
3 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/Makefile

    r7892 r7938  
    66### the include file dependencies need to be cleaned up still
    77
    8 mana:  lib.data lib.shell cmd.basic cmd.data cmd.astro
    9 dimm:  lib.data lib.shell cmd.basic cmd.data cmd.astro
    10 dvo:   lib.data lib.shell cmd.basic cmd.data cmd.astro
    11 pantasks: lib.data lib.shell cmd.basic cmd.data cmd.astro
    12 pclient:  lib.data lib.shell cmd.basic
    13 pcontrol: lib.data lib.shell cmd.basic
    14 
     8mana:            lib.data lib.shell cmd.basic cmd.data cmd.astro
     9dimm:            lib.data lib.shell cmd.basic cmd.data cmd.astro
     10dvo:             lib.data lib.shell cmd.basic cmd.data cmd.astro
     11pantasks:        lib.data lib.shell cmd.basic cmd.data cmd.astro
    1512pantasks_server: lib.data lib.shell cmd.basic cmd.data cmd.astro
    1613pantasks_client: lib.data lib.shell cmd.basic cmd.data cmd.astro
     14pclient:         lib.data lib.shell cmd.basic
     15pcontrol:        lib.data lib.shell cmd.basic
    1716
    1817LIBS = lib.data lib.shell cmd.basic cmd.data cmd.astro
     
    2423all:
    2524        for i in $(PROGRAM); do make $$i || exit; done
     25        make pantasks_client
     26        make pantasks_server
    2627
    2728libs:
     
    3334install:
    3435        for i in $(PROGRAM); do make $$i.install || exit; done
     36        make pantasks_client.install
     37        make pantasks_server.install
    3538
    3639extras-install:
     
    5356        if [ -d pantasks ]; then (cd pantasks && make $@); fi
    5457
    55 pantasks_client.install pantasks_server.install:
     58pantasks_client.install: pantasks_client
     59        if [ -d pantasks ]; then (cd pantasks && make $@); fi
     60
     61pantasks_server.install: pantasks_server
    5662        if [ -d pantasks ]; then (cd pantasks && make $@); fi
    5763
     
    7278        if [ -d "$*" ]; then (cd $* && make uninstall); fi
    7379
    74 .PHONY: $(PROGRAM) $(LIBS)
    75 
     80.PHONY: $(PROGRAM) $(LIBS) pantasks_server pantasks_client
  • trunk/Ohana/src/opihi/cmd.basic/output.c

    r7917 r7938  
    55int output (int argc, char **argv) {
    66 
    7   int N;
     7  int N, Noutput;
    88  gpDest dest;
    99  IOBuffer *buffer;
     10  char *output;
    1011
    1112  dest = GP_LOG;
     
    2122  }
    2223   
     24  /* set the output target and dump the current buffer there */
    2325  if ((N = get_argument (argc, argv, "-dump"))) {
     26    buffer = gprintGetBuffer (dest);
     27
     28    /* save the current buffer contents */
     29    Noutput = buffer[0].Nbuffer;
     30    ALLOCATE (output, char, Noutput);
     31    memcpy (output, buffer[0].buffer, Noutput);
     32   
     33    /* set the output target to the specified name */
    2434    remove_argument (N, &argc, argv);
    25     buffer = gprintGetBuffer (dest);
    26     fprintf (STDERR, "buffer contents: \n");
    27     fwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, stderr);
    28     fprintf (STDERR, "\n");
     35    gprintSetFile (dest, argv[N]);
     36    remove_argument (N, &argc, argv);
     37
     38    /* send the output to the appropriate destination */
     39    gwrite (output, 1, Noutput, dest);
    2940    return (TRUE);
    3041  }
    3142   
    3243  if (argc != 2) {
    33     gprint (GP_ERR, "USAGE: output <filename>\n");
     44    gprint (GP_ERR, "USAGE: output <filename> [-err] [-buffer] [-dump filename]\n");
    3445    return (FALSE);
    3546  }
     
    4657  outfile = stdout;
    4758}
    48 
    49 /* we could add the concept of saving the output to a buffer
    50    then dumping to the target of the output stream.  not sure
    51    what the command should look like... */
  • trunk/Ohana/src/opihi/include/shell.h

    r7929 r7938  
    4848void          startup                   PROTO((int *argc, char **argv));
    4949int           multicommand              PROTO((char *line));
    50 int           command                   PROTO((char *, char **));
    51 int           multicommand_client       PROTO((char *line, int));
    52 int           command_client            PROTO((char *, char **));
     50void          multicommand_InitServer   PROTO((void));
     51int           command                   PROTO((char *line, char **outline, int VERBOSE));
    5352char         *expand_vars               PROTO((char *line));
    5453char         *expand_vectors            PROTO((char *line));
  • trunk/Ohana/src/opihi/lib.data/open_graph.c

    r7917 r7938  
    11# include "display.h"
     2# include "shell.h"
    23# define DEBUG 0
    34
  • trunk/Ohana/src/opihi/lib.data/open_image.c

    r7917 r7938  
    11# include "display.h"
     2# include "shell.h"
    23# define DEBUG 0
    34
  • trunk/Ohana/src/opihi/lib.shell/Makefile

    r7929 r7938  
    2121$(SDIR)/ListOps.$(ARCH).o               \
    2222$(SDIR)/command.$(ARCH).o               \
    23 $(SDIR)/command_client.$(ARCH).o        \
    2423$(SDIR)/CommandOps.$(ARCH).o            \
    2524$(SDIR)/errors.$(ARCH).o                \
     
    3837$(SDIR)/memstr.$(ARCH).o                \
    3938$(SDIR)/multicommand.$(ARCH).o          \
    40 $(SDIR)/multicommand_client.$(ARCH).o   \
    4139$(SDIR)/parse.$(ARCH).o                 \
    4240$(SDIR)/parse_commands.$(ARCH).o        \
     
    4543$(SDIR)/timeformat.$(ARCH).o            \
    4644$(SDIR)/BufferOps.$(ARCH).o             \
     45$(SDIR)/SocketOps.$(ARCH).o             \
    4746$(SDIR)/VectorOps.$(ARCH).o             \
    4847$(SDIR)/check_stack.$(ARCH).o           \
  • trunk/Ohana/src/opihi/lib.shell/command.c

    r7917 r7938  
    11# include "opihi.h"
    2 # define VERBOSE 0
     2# define DEBUG 0
    33
    4 int command (char *line, char **outline) {
     4int command (char *line, char **outline, int VERBOSE) {
    55
    66  int i, status, argc;
     
    2626  *outline = line;
    2727 
     28  # if (DEBUG)
     29  fprintf (stderr, "line: %s\n", line);
     30  # endif
     31
    2832  argv = parse_commands (line, &argc);
    2933  if (argc == 0) return (TRUE);  /* empty command or assignment */
     
    3337  for (i = 0; i < argc; i++) targv[i] = argv[i];
    3438
    35   cmd = MatchCommand (argv[0], TRUE, FALSE);
     39  cmd = MatchCommand (argv[0], VERBOSE, FALSE);
    3640  if (cmd == NULL) {
    37     status = FALSE;
     41    status = -1;
    3842  } else {
    3943    free (argv[0]);
     
    5357
    5458  set_int_variable ("STATUS", status);
    55   if (VERBOSE) gprint (GP_ERR, "command: %s, status: %d\n", line, status);
     59
     60  # if (DEBUG)
     61  gprint (GP_ERR, "command: %s, status: %d\n", line, status);
     62  # endif
     63
    5664  return (status);
    5765}
     66
     67/* parse the input line, search for the corresponding command, and execute it
     68   if no match is found, return -1; this is used above to distinguish between
     69   a command error and an unknown command.  if VERBOSE is true, unknown commands
     70   result in an error message.  The input line is freed and the resulting parsed
     71   line is returned on 'outline'
     72*/
  • trunk/Ohana/src/opihi/lib.shell/exec_loop.c

    r4462 r7938  
    3030    lists[ThisList].n = n;
    3131    line = lists[ThisList].line[n];
     32
    3233    status = multicommand (line);
     34
    3335    if (line != NULL) free (line);
    3436    n = lists[ThisList].n;
  • trunk/Ohana/src/opihi/lib.shell/multicommand.c

    r4689 r7938  
    11# include "opihi.h"
     2
     3static int server = 0;
     4
     5void multicommand_InitServer () {
     6
     7  char hostname[256], PASSWORD[256];
     8
     9  if (server != 0) {
     10    /* check if down? */
     11    fprintf (stderr, "error: server fd already defined\n");
     12    exit (1);
     13  }
     14
     15  /* find the defined server hostname */
     16  if (VarConfig ("PANTASKS_SERVER", "%s", hostname) == NULL) {
     17    gprint (GP_ERR, "pantasks server host undefined\n");
     18    exit (2);
     19  }
     20
     21  /* attempt to connect to the server */
     22  server = GetClientSocket (hostname);
     23
     24  /* here we can perform the security handshaking */
     25  VarConfig ("PASSWORD", "%s", PASSWORD);
     26  SendCommand (server, strlen(PASSWORD), PASSWORD);
     27 
     28  return;
     29}
    230
    331/* take input line and split into multiple lines
     
    634int multicommand (char *line) {
    735 
    8   int done, status;
     36  int done, status, verbose;
    937  char *p, *q, *tmpline, *outline;
     38  IOBuffer message;
     39
     40  /* if no server is defined, use 'verbose' mode for 'command' */
     41  verbose = (server == 0);
    1042
    1143  p = line;
     
    2153    stripwhite (tmpline);
    2254    if (*tmpline) {
    23       status = command (tmpline, &outline);
     55
     56      status = command (tmpline, &outline, verbose);
     57
     58      if (status == -1) {
     59        if (server) {
     60          // send the command to the server instead
     61          if (!SendMessage (server, outline)) {
     62            switch (errno) {
     63              case EPIPE:
     64                gprint (GP_ERR, "server connection has died\n");
     65                exit (1);
     66              default:
     67                gprint (GP_ERR, "I/O error sending server message\n");
     68                exit (2);
     69            }
     70          }
     71
     72          // receive the resulting stderr
     73          if (ExpectMessage (server, 2.0, &message)) {
     74            switch (errno) {
     75              case EPIPE:
     76                gprint (GP_ERR, "server connection has died\n");
     77                exit (1);
     78              default:
     79                gprint (GP_ERR, "I/O error sending server message\n");
     80                exit (2);
     81            }
     82          } else {
     83            gwrite (message.buffer, 1, message.Nbuffer, GP_ERR);
     84          }
     85
     86          // receive the resulting stdout
     87          if (ExpectMessage (server, 2.0, &message)) {
     88            switch (errno) {
     89              case EPIPE:
     90                gprint (GP_ERR, "server connection has died\n");
     91                exit (1);
     92              default:
     93                gprint (GP_ERR, "I/O error sending server message\n");
     94                exit (2);
     95            }
     96          } else {
     97            gwrite (message.buffer, 1, message.Nbuffer, GP_LOG);
     98          }
     99        } else {
     100          // if no server is defined, we treat an unknown command as an error
     101          status = FALSE;
     102        }       
     103      }
     104
    24105      if (outline != NULL) free (outline);
    25106      if (!status && auto_break) done = TRUE;
     
    31112
    32113/* should skip ; surrounded by "" */
     114
     115/* commands which are not found are sent to the server socket if
     116   defined. commands executed by the server return their stderr
     117   and stdout streams.  server commands should probably not block
     118   the server for very long or multiple clients will interfere
     119   with each other. 
     120*/
  • trunk/Ohana/src/opihi/lib.shell/startup.c

    r7917 r7938  
    121121      rcfile = get_variable ("RCFILE");
    122122      sprintf (line, "input %s/%s", home, rcfile);
    123       status = command (line, &outline);
     123      status = command (line, &outline, TRUE);
    124124      if (outline != (char *) NULL) free (outline);
    125125    }
     
    144144      ALLOCATE (line, char, 1024);
    145145      sprintf (line, "input %s", list[i]);
    146       status = command (line, &outline);
     146      status = command (line, &outline, TRUE);
    147147      if (outline != (char *) NULL) free (outline);
    148148    }
  • trunk/Ohana/src/opihi/pantasks/ListenClients.c

    r7929 r7938  
    66static int *clients;
    77static IOBuffer *buffers;
    8 
    9 /* outline of functions we need here */
    108
    119void InitClients () {
     
    1715}
    1816
     17/* add this client to the client table, create an IOBuffer for it */
    1918void AddNewClient (int client) {
    20 
    21   /* add this client to the client table */
    22   /* need to create an IOBuffer for each possible client?
    23      we may not read a complete line in one pass.  have to
    24      wait until we get the complete lines...
    25   */
    2619
    2720  if (DEBUG) gprint (GP_LOG, "adding a new client (%d)\n", client);
     
    3629}
    3730
     31/* select for messages from the current clients; wait for 0.5s before updating client list */
    3832void *ListenClients (void *data) {
    3933 
     
    4842  gprintInit ();  // each thread needs to init the printing system
    4943
    50   while (0) {
    51 
    52     Ncurrent = Nclients;
    53     for (i = 0; i < Ncurrent; i++) {
    54       ExpectMessage (clients[i], 0.25, &buffers[i]);
    55       if (DEBUG) gprint (GP_ERR, "read %d from client %d\n", buffers[i].Nbuffer, i);
    56       if (buffers[i].Nbuffer) {
    57         if (DEBUG) gprint (GP_ERR, "%s\n", buffers[i].buffer);
    58       }
    59     }
    60     usleep (250000);
    61   }
    62 
    6344  while (1) {
    6445
    6546    /* Wait up to 0.5 second - need to timeout to update client list */
    6647    /* timeout gets mucked: need to reset before each select */
    67     timeout.tv_sec = 1;
    68     timeout.tv_usec = 000000;
     48    timeout.tv_sec = 0;
     49    timeout.tv_usec = 500000;
    6950
    7051    /* place all of the clients in the fdSet */
  • trunk/Ohana/src/opihi/pantasks/Makefile

    r7929 r7938  
    7070$(SDIR)/client_shell.$(ARCH).o \
    7171$(SDIR)/invalid.$(ARCH).o \
    72 $(SDIR)/init_client.$(ARCH).o \
    73 $(SDIR)/SocketOps.$(ARCH).o
     72$(SDIR)/init_client.$(ARCH).o
    7473
    7574server = \
    7675$(SDIR)/pantasks_server.$(ARCH).o \
    7776$(SDIR)/ListenClients.$(ARCH).o \
    78 $(SDIR)/CheckPassword.$(ARCH).o \
    79 $(SDIR)/SocketOps.$(ARCH).o
     77$(SDIR)/CheckPassword.$(ARCH).o
    8078
    8179libs = \
  • trunk/Ohana/src/opihi/pantasks/client_shell.c

    r7929 r7938  
    55
    66  int i, Nbad, status, server;
    7   char *line, *outline, *prompt, *history;
    8   char hostname[256], PASSWORD[256];
     7  char *line, *prompt, *history;
    98  pid_t ppid;
    10   IOBuffer message;
    119
    1210  general_init (&argc, argv);
     
    1715  welcome ();
    1816
    19   /* connect to the server */
    20   if (VarConfig ("PANTASKS_SERVER", "%s", hostname) == NULL) {
    21     gprint (GP_ERR, "pantasks server host undefined\n");
    22     exit (2);
    23   }
    24   server = GetClientSocket (hostname);
     17  /* attempt to connect to the pantasks server (exit on failure) */
     18  multicommand_InitServer ();
    2519
    26   /* here we can perform the security handshaking */
    27   VarConfig ("PASSWORD", "%s", PASSWORD);
    28   SendCommand (server, strlen(PASSWORD), PASSWORD);
    29  
    3020  Nbad = 0;
    3121  while (1) {  /** must exit with command "exit" or "quit" */
     
    5040
    5141    stripwhite (line);
    52    
    53     /* check for commands to be caught by client */
    54     /* use the standard command parser? */
    55     /* XXX the exit status of command does not allow us
    56        to distinguish 'failed command' and 'command not found' */
    57     /* XXX eventually replace this with a multicommand parsing */
    58     status = multicommand_client (line, server);
    59     add_history (line);
    60     append_history (1, history);
    6142
     43    if (*line) {
     44        status = multicommand (line);
     45        add_history (line);
     46        append_history (1, history);
     47    }
    6248    free (line);
    6349  }
    6450}
    65 
    66 # if 0
    67     /* command was not caught by client, send to server */
    68     if (*outline && !status ) {
    69       gprint (GP_ERR, "sending message to %d: %s\n", server, outline);
    70       SendMessage (server, outline);
    71       add_history (outline);
    72       append_history (1, history);
    73 
    74       // XXX add this in and print to stdout
    75       status = ExpectMessage (server, 2.0, &message);
    76       // fprintf (stderr, "got stdout message: %d bytes\n", message.Nbuffer);
    77       fwrite (message.buffer, 1, message.Nbuffer, stderr);
    78       // fprintf (stderr, "end message\n");
    79 
    80       // fprintf (stderr, "got message: %d bytes\n", message.Nbuffer);
    81       // for (i = 0; i < message.Nbuffer; i++) {
    82       // fprintf (stderr, "%d %d %c\n", i, message.buffer[i], message.buffer[i]);
    83       // }
    84       // fwrite (message.buffer, 1, message.Nbuffer, stderr);
    85       // fprintf (stderr, "end message\n");
    86 
    87       // XXX add this in and print to stdout
    88       status = ExpectMessage (server, 2.0, &message);
    89       // fprintf (stderr, "got stderr message: %d bytes\n", message.Nbuffer);
    90       fwrite (message.buffer, 1, message.Nbuffer, stderr);
    91       // fprintf (stderr, "end message\n");
    92     }
    93 # endif
    9451
    9552/*
  • trunk/Ohana/src/opihi/pantasks/pantasks_client.c

    r7929 r7938  
    1010void program_init (int *argc, char **argv) {
    1111 
     12  auto_break = TRUE;
     13
    1214  /* load the commands used by this implementation */
    1315  InitBasic ();
    1416  InitData ();
     17  InitAstro ();
    1518  InitPantasksClient ();
    1619
     
    1922  rl_readline_name = opihi_name;
    2023  rl_attempted_completion_function = command_completer;
    21   rl_event_hook = NULL;
    22   rl_set_keyboard_input_timeout (100000);
    2324
    2425  set_str_variable ("HISTORY", opihi_history);
     
    2627  set_str_variable ("RCFILE", opihi_rcfile);
    2728
    28   /* should we trap some commands and exec them locally? */
    29   /* help would be an obvious example... */
    3029# ifdef HELPDIR_DEFAULT
    3130  set_str_variable ("HELPDIR", MACRO_NAME(HELPDIR_DEFAULT));
     
    4544
    4645/* add program-dependent exit functions here */
    47 /* unclear what we should do with the plotting functions:
    48    do we keep the data only on the server, with all plotting
    49    taking place on the server? or what? */
    5046void cleanup () {
    51   // QuitImage ();
    52   // QuitGraph ();
     47  QuitImage ();
     48  QuitGraph ();
    5349  return;
    5450}
     
    6056}
    6157
    62 /* call to opihi shell */
     58/* call to client_shell: this opihi tool uses a slightly different
     59   shell function from the standard tools */
    6360int main (int argc, char **argv) {
    6461  int status;
Note: See TracChangeset for help on using the changeset viewer.