Beispiel #1
0
bool provider_register(char *name, uint64_t channel_id)
{
  Feature *f = find_feature(name);

  if (!f) {
    return false;
  }

  if (f->channel_id && channel_exists(f->channel_id)) {
    ILOG("Feature \"%s\" is already provided by another channel"
         "(will be replaced)", name);
  }

  DLOG("Registering provider for \"%s\"", name);
  f->channel_id = channel_id;

  // Associate all method names with the feature struct
  size_t i;
  char *method;
  for (method = f->methods[i = 0]; method; method = f->methods[++i]) {
    pmap_put(cstr_t)(registered_providers, method, f);
    DLOG("Channel \"%" PRIu64 "\" will be sent requests for \"%s\"",
         channel_id,
         method);
  }

  ILOG("Registered channel %" PRIu64 " as the provider for the \"%s\" feature",
       channel_id,
       name);

  return true;
}
Beispiel #2
0
static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,
                               Array args, Error *error)
{
  if (pmap_has(uint64_t)(connected_uis, channel_id)) {
    api_set_error(error, Exception, _("UI already attached for channel"));
    return NIL;
  }

  if (args.size != 3 || args.items[0].type != kObjectTypeInteger
      || args.items[1].type != kObjectTypeInteger
      || args.items[2].type != kObjectTypeBoolean
      || args.items[0].data.integer <= 0 || args.items[1].data.integer <= 0) {
    api_set_error(error, Validation,
                  _("Invalid arguments. Expected: "
                    "(uint width > 0, uint height > 0, bool enable_rgb)"));
    return NIL;
  }
  UIData *data = xmalloc(sizeof(UIData));
  data->channel_id = channel_id;
  data->buffer = (Array)ARRAY_DICT_INIT;
  UI *ui = xcalloc(1, sizeof(UI));
  ui->width = (int)args.items[0].data.integer;
  ui->height = (int)args.items[1].data.integer;
  ui->rgb = args.items[2].data.boolean;
  ui->data = data;
  ui->resize = remote_ui_resize;
  ui->clear = remote_ui_clear;
  ui->eol_clear = remote_ui_eol_clear;
  ui->cursor_goto = remote_ui_cursor_goto;
  ui->busy_start = remote_ui_busy_start;
  ui->busy_stop = remote_ui_busy_stop;
  ui->mouse_on = remote_ui_mouse_on;
  ui->mouse_off = remote_ui_mouse_off;
  ui->insert_mode = remote_ui_insert_mode;
  ui->normal_mode = remote_ui_normal_mode;
  ui->set_scroll_region = remote_ui_set_scroll_region;
  ui->scroll = remote_ui_scroll;
  ui->highlight_set = remote_ui_highlight_set;
  ui->put = remote_ui_put;
  ui->bell = remote_ui_bell;
  ui->visual_bell = remote_ui_visual_bell;
  ui->update_fg = remote_ui_update_fg;
  ui->update_bg = remote_ui_update_bg;
  ui->flush = remote_ui_flush;
  ui->suspend = remote_ui_suspend;
  ui->set_title = remote_ui_set_title;
  ui->set_icon = remote_ui_set_icon;
  pmap_put(uint64_t)(connected_uis, channel_id, ui);
  ui_attach(ui);
  return NIL;
}