Exemple #1
0
int call_callback(HCALLBACK cb, const char *name, ...) {
    va_list ap;
    if (name) {
        int err = find_callback(name, &cb);
        if (err) return err;
    }
    va_start(ap, name);
    cb.cbv(ap);
    va_end(ap);
    return 0;
}
static void
invoke_callback3(const mc_PACKET *pkt,
    lcb_t instance,lcb_CALLBACKTYPE cbtype, lcb_RESPBASE * resp)
{
    if (!(pkt->flags & MCREQ_F_INVOKED)) {
        resp->cookie = (void *)MCREQ_PKT_COOKIE(pkt);
        if ((pkt->flags & MCREQ_F_PRIVCALLBACK) == 0) {
            find_callback(instance, cbtype)(instance, cbtype, resp);
        } else {
            (*(lcb_RESPCALLBACK*)resp->cookie)(instance, cbtype, resp);
        }
    }
}
efsw_watchid efsw_addwatch(efsw_watcher watcher, const char* directory,
	efsw_pfn_fileaction_callback callback_fn, int recursive, void * param)
{
	Watcher_CAPI* callback = find_callback(watcher, callback_fn);

	if (callback == NULL)   {
		callback = new Watcher_CAPI(watcher, callback_fn, param);
		g_callbacks.push_back(callback);
	}

	return ((efsw::FileWatcher*)watcher)->addWatch(std::string(directory), callback,
		TOBOOL(recursive));
}
Exemple #4
0
/*
 * call-seq:
 *    Win32::API::Callback.new(prototype, return='L'){ |proto| ... }
 *
 * Creates and returns a new Win32::API::Callback object. The prototype
 * arguments are yielded back to the block in the same order they were
 * declared.
 *
 * The +prototype+ is the function prototype for the callback function. This
 * is a string. The possible valid characters are 'I' (integer), 'L' (long),
 * 'V' (void), 'P' (pointer) or 'S' (string). Unlike API objects, API::Callback
 * objects do not have a default prototype.
 *
 * The +return+ argument is the return type for the callback function. The
 * valid characters are the same as for the +prototype+. The default is
 * 'L' (long).
 *
 * Example:
 *    require 'win32/api'
 *    include Win32
 *
 *    EnumWindows = API.new('EnumWindows', 'KP', 'L', 'user32')
 *    GetWindowText = API.new('GetWindowText', 'LPI', 'I', 'user32')
 *
 *    EnumWindowsProc = API::Callback.new('LP', 'I'){ |handle, param|
 *       buf = "\0" * 200
 *       GetWindowText.call(handle, buf, 200);
 *       puts buf.strip unless buf.strip.empty?
 *       buf.index(param).nil? ? true : false
 *    }
 *
 *    EnumWindows.call(EnumWindowsProc, 'UEDIT32')
 */
static VALUE callback_init(int argc, VALUE* argv, VALUE self)
{
   void *find_callback(VALUE,int);
   VALUE v_proto, v_return, v_proc;
   int i;

   rb_scan_args(argc, argv, "11&", &v_proto, &v_return, &v_proc);

   /* Validate prototype characters */
   for(i = 0; i < RSTRING_LEN(v_proto); i++){
      switch(RSTRING_PTR(v_proto)[i]){
         case 'I': case 'L': case 'P': case 'V': case 'S':
            break;
         default:
            rb_raise(cAPIProtoError, "Illegal prototype '%c'",
               RSTRING_PTR(v_proto)[i]
            );
      }
   }

   if(NIL_P(v_return) || RARRAY_LEN(v_return) == 0){
      v_return = rb_str_new2("L");
   }
   else{
      switch(*(char*)RSTRING_PTR(v_return)){
         case 'I': case 'L': case 'P': case 'V': case 'S':
            break;
         default:
            rb_raise(cAPIProtoError, "Illegal return type '%s'",
               RSTRING_PTR(v_return)
            );
      }
   }

   rb_iv_set(self, "@function", v_proc);
   rb_iv_set(self, "@prototype", v_proto);
   rb_iv_set(self, "@return_type", v_return);
   rb_iv_set(self, "@address", ULONG2NUM((LPARAM)find_callback(self,RSTRING_LEN(v_proto))));
   ActiveCallback = self;

   return self;
}
static void uv__codius_async_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
  size_t bytes_read;
  codius_rpc_header_t rpc_header;
  const int fd = 3;

  const char* message = "{\"type\":\"request_async_response\"}";
  
  // char resp_buf[UV_SYNC_MAX_MESSAGE_SIZE];
  // int resp_len;
  // resp_len = uv_sync_call(message, len, resp_buf, sizeof(resp_buf));

  rpc_header.magic_bytes = CODIUS_MAGIC_BYTES;
  rpc_header.callback_id = 0;
  rpc_header.size = strlen(message);
  
  if (-1==write(fd, &rpc_header, sizeof(rpc_header)) ||
      -1==write(fd, message, strlen(message))) {
    perror("write()");
    //TYPE_ERROR("Error writing to sync fd 4");
    return -1;
  }
  
  bytes_read = read(fd, &rpc_header, sizeof(rpc_header));
  if (rpc_header.magic_bytes!=CODIUS_MAGIC_BYTES) {
    //TYPE_ERROR("Error reading sync fd 4, invalid header");
    return -1;
  }
  
  // No asynchronous responses found.
  if (rpc_header.size==0) {
    return;
  }

  char buf[rpc_header.size];
  bytes_read = read(fd, &buf, rpc_header.size);

  callback_list_t *cb_list;
  if (bytes_read && bytes_read!=-1) {
    cb_list = find_callback(loop, rpc_header.callback_id);
    cb_list->work->done(cb_list->work, 0, buf, rpc_header.size);
  }
}
Exemple #6
0
int tclcommand_setmd(ClientData data, Tcl_Interp *interp,
	  int argc, char **argv)
{
  union {
    int    intbuf[MAX_DIMENSION];
    double doublebuf[MAX_DIMENSION];
  } databuf;
  char buffer[TCL_DOUBLE_SPACE + 5];
  int i, j;
  int all = (argc == 1), writing = (argc >= 3);

  /* loop over all global variables. Has two purposes:
     either we write al variables or search for the one
     to write */
  for (i = 0; fields[i].data != NULL; i++) {
    if (all || !strncmp(argv[1], fields[i].name, strlen(argv[1]))) {
      if (!all) {
	if ((int)strlen(argv[1]) < fields[i].min_length) {
	  Tcl_AppendResult(interp, "Argument \"",argv[1],"\" not long ", (char *) NULL);
	  Tcl_AppendResult(interp, "enough to identify a setmd variable!", (char *) NULL);
	  return (TCL_ERROR);
	}
	if (writing) {
	  /* set */
	  /* parse in data */
	  if (argc != 2 + fields[i].dimension) {
	    sprintf(buffer, "%d", fields[i].dimension);	  
	    Tcl_AppendResult(interp, "\"", argv[1],
			     "\" has dimension ",
			     buffer, (char *) NULL);
	    sprintf(buffer, " not %d", argc - 2);	  
	    Tcl_AppendResult(interp, buffer, (char *) NULL);
	    return (TCL_ERROR);
	  }

	  /* get new value */
	  for (j = 0; j < fields[i].dimension; j++) {
	    switch (fields[i].type) {
	    case TYPE_INT:
	      if (Tcl_GetInt(interp, argv[2 + j], databuf.intbuf + j) == TCL_ERROR)
		return (TCL_ERROR);
	      break;
	    case TYPE_BOOL: {
	      int dta;
	      if (Tcl_GetInt(interp, argv[2 + j], &dta))
		return (TCL_ERROR);
	      if (dta) {
		databuf.intbuf[0] |= (1L << j);
	      } else {
		databuf.intbuf[0] &= ~(1L << j);
	      }
	      break;
	    }
	    case TYPE_DOUBLE:
	      if (Tcl_GetDouble(interp, argv[2 + j], databuf.doublebuf + j))
		return (TCL_ERROR);
	      break;
	    default: ;
	    }
	  }

	  if (find_callback(i)(interp, databuf.intbuf) != TCL_OK)
	    return gather_runtime_errors(interp, TCL_ERROR);
	  /* fall through to write out the set value immediately again */
	}
      }

      /* get */
      if (all) {
	if (i != 0)
	  Tcl_AppendResult(interp, " ", (char *)NULL);
	Tcl_AppendResult(interp, "{", fields[i].name, " ", (char *)NULL);
      }
      for (j = 0; j < fields[i].dimension; j++) {
	switch (fields[i].type) {
	case TYPE_INT:
	  sprintf(buffer, "%d", ((int *)fields[i].data)[j]);
	  break;
	case TYPE_BOOL: {
	  if ((*(int *)fields[i].data) & (1L << j))
	    strcpy(buffer, "1");
	  else
	    strcpy(buffer, "0");
	  break;
	}
	case TYPE_DOUBLE:
	  Tcl_PrintDouble(interp, ((double *)fields[i].data)[j], buffer);
	  break;
	default: ;
	}
	Tcl_AppendResult(interp, buffer, (char *) NULL);
	if (j < fields[i].dimension - 1)
	  Tcl_AppendResult(interp, " ", (char *) NULL);
      }
      
      if (all)
	Tcl_AppendResult(interp, "}", (char *)NULL);
      /* wrote out one value, so skip rest */
      if (!all) {
	if (writing)
	  return gather_runtime_errors(interp, TCL_OK);
	else
	  return (TCL_OK);
      }
    }
  }
  if (all)
    return TCL_OK;

  Tcl_AppendResult(interp, "unknown md variable \"",
		   argv[1], "\"", (char *) NULL);
  return (TCL_ERROR);
}
Exemple #7
0
void
_modinit(void)
{
  if ((info_cb = find_callback("doing_info")))
    prev_hook = install_hook(info_cb, show_info);
}
void
_modinit(void)
{
  if ((stats_cb = find_callback("doing_stats")))
    prev_hook = install_hook(stats_cb, show_stats);
}
void
_modinit(void)
{
  if ((admin_cb = find_callback("doing_admin")))
    prev_hook = install_hook(admin_cb, show_admin);
}
Exemple #10
0
void
_modinit(void)
{
  if ((links_cb = find_callback("doing_links")))
    prev_hook = install_hook(links_cb, show_links);
}