Ejemplo n.º 1
0
static void signal_handler(int sig)
{
#ifdef USE_TIDE
    if(use_tide)
        ATBwriteTerm(tide_cid, ATparse("snd-disconnect"));
#endif
    if(use_toolbus)
        ATBwriteTerm(cid, ATparse("snd-disconnect"));

    exit(1);
}
Ejemplo n.º 2
0
void rec_terminate(int conn, ATerm arg)
{
  int cid;

  ATfprintf(stderr, "rec_terminate %t: conn=%d, master_cid=%d\n",
	    arg, conn, master_cid);
  if (conn == master_cid) {
    for (cid=0; cid<=max_cid; cid++) {
      if (cid != master_cid && ATBisValidConnection(cid)) {
	ATBwriteTerm(cid, ATparse("snd-event(toolbus-stop)"));
      }
    }
    exit(0);
  }
}
Ejemplo n.º 3
0
int Tcl_TBsend(ClientData data, Tcl_Interp *interp, int argc, char *argv[])
{
    ATerm t;

    if(argc != 2) {
        interp->result = "Usage: TBsend ?term?";
        return TCL_ERROR;
    }

    t = TclString2Term(argv[1]);

    if(use_toolbus)
        ATBwriteTerm(cid, t);
    else
        ATprintf("ATBwriteTerm: %t\n", t);

    return TCL_OK;
}
Ejemplo n.º 4
0
void toolbus_stop(int conn, int id)
{
  ATBwriteTerm(id, ATparse("toolbus-stop"));
}
Ejemplo n.º 5
0
/*
 *  This function is registered as a handler for HTTP methods and will
 *  therefore be invoked for all GET requests (and others).
 *  In this type of request handler, stderr is redirected to a httpd log file
 *  (default: <apache_dir>/logs/error.log)
 *  TODO:
 *    - use apr_... functions (Apache Portable Runtime for Apache 2.0) 
 *      instead of ap_... ones where applicable
 */
static int http_req_handler( request_rec *http_req )
{
  /* toolbus initialization */
  ATerm BottomOfStack;          /* used by ATBinit(), don't move */
  char* tb_init_argv[] =           /* used to set up TB connection */
    {
      "this_is_a_spacefiller_dummy", 
      "-TB_TOOL_NAME", TB_TOOL_NAME_VALUE 
    };
  int tb_init_argc = 4;
  int tb_conn;              /* set by ATBconnect() */
  
  /* toolbus communication */
  ATerm tb_event_to_send;
  ATerm tb_args;
    
  char args_ascii[SEND_BUF_SIZE];  
  
  /* these are used for control flow in the toolbus section */
  int count;

  /* init toolbus  module */
  ATBinit( tb_init_argc, tb_init_argv, &BottomOfStack );
 
  /* update global variable so the toolbus handler can use it too */
  global_http_req = http_req;
    
  /* print some debugging info to the log file */
  fprintf( stderr, "mod_toolbus: invoked with pid=%d, ppid=%d\n",
      (int) getpid(), (int) getppid() );
  fflush( stderr );
  
  /* check if this is a toolbus request, otherwise we don't handle it */
  if( strcmp( global_http_req->uri, MOD_TOOLBUS_NAME_URI ) ) 
  {
    return DECLINED;
  }

    ap_set_content_type( global_http_req, "text/html" );
    if( global_http_req->header_only ) { return OK; }

  #ifdef VERBOSE
    dump_http_req_fields( global_http_req );
  #endif
  
  /*
   *  read event to send from HTTP request arguments, validate
   *  filter, and prepare it to be sent to the toolbus
   */
  utf8_to_ascii(args_ascii , global_http_req->args );
  fprintf( stderr, "args: %s\n", global_http_req->args  );
  fprintf( stderr, "send_buf_ascii %s\n", args_ascii );

  if ((tb_args = parseHTTPArgs(args_ascii)) == NULL) {
    ap_rprintf(global_http_req, "parse error in %s\n", args_ascii);
    return OK;
  }

  /*
   *  The toolbus part starts here.
   *  We connect to the toolbus and send an event to it.
   */    
  fprintf( stderr, "mod_toolbus: connecting to Toolbus...\n" );
  fflush( stderr );
  
  /*
   *  Check if our flag is nonzero. It should only be set by our 
   *  toolbus_handler(), which has not yet been called at this point. 
   *  If it is nonzero, something is wrong, and we may have encountered some
   *  race conditions (i.e. thread-unsafety).
   */
  if( global_is_tb_session_done > 0 )
  {
    mod_toolbus_fatal( 
      "global_is_tb_session_done >0 before toolbus_handler() called." );  
  }
  

  /* connect to toolbus and install our handler: toolbus_handler() */
  if( (tb_conn = ATBconnect( NULL, NULL, TOOLBUS_PORT, toolbus_handler )) >= 0 )
  {
    count = 1;        /* send one event */
    while( global_is_tb_session_done == 0 )
    {
      /* check if data is waiting on the toolbus connection */
      if( ATBpeekOne( tb_conn ) )
      {
        fprintf( stderr, "mod_toolbus: received another event.\n" );
        fflush(stderr );
        /* invoke handler "toolbus_handler()" via ATBhandleOne() */
        if( ATBhandleOne( tb_conn ) < 0 )
        {
          fprintf( stderr, 
            "mod_toolbus: ATBhandleOne() returned error\n" );
          fflush(stderr );
          return -1;
        }
      }
      else  /* no data waiting on tb_conn so we can send some */
      {
        if( count ) /* send an event to the toolbus */
        { 
          ATBwriteTerm(tb_conn, ATmake("snd-event(request(<term>))", tb_args));
          ATfprintf(stderr, "\nsending event to toolbus: %t\n",
		    ATmake( "snd-event(request(<term>))", tb_args ) );
          fflush(stderr);
          count --;
        } 
      }
    }
    fprintf( stderr, "mod_toolbus: disconnecting from toolbus...\n" );
    fflush( stderr );
    ATBdisconnect( tb_conn );
    
  } 
  else
  {
    fprintf( stderr, "mod_toolbus: could not connect to toolbus\n" );
    fflush( stderr );
  }  
     
  fprintf( stderr,"mod_toolbus: leaving handler\n");
  fflush( stderr );

  return OK;
}