示例#1
0
/* Each FD may have at most one valid dispatcher.
 * If a new dispatch is added for an FD, the old one is removed.
 * mode determines what types of events are watched for, and may be any combination of:
 * OWL_IO_READ, OWL_IO_WRITE, OWL_IO_EXCEPT
 */
const owl_io_dispatch *owl_select_add_io_dispatch(int fd, int mode, void (*cb)(const owl_io_dispatch *, void *), void (*destroy)(const owl_io_dispatch *), void *data)
{
  owl_io_dispatch *d = g_new(owl_io_dispatch, 1);
  owl_list *dl = owl_global_get_io_dispatch_list(&g);
  owl_io_dispatch *other;

  d->fd = fd;
  d->valid = true;
  d->needs_gc = 0;
  d->mode = mode;
  d->callback = cb;
  d->destroy = destroy;
  d->data = data;

  /* TODO: Allow changing fd and mode in the middle? Probably don't care... */
  d->pollfd.fd = fd;
  d->pollfd.events = 0;
  if (d->mode & OWL_IO_READ)
    d->pollfd.events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
  if (d->mode & OWL_IO_WRITE)
    d->pollfd.events |= G_IO_OUT | G_IO_ERR;
  if (d->mode & OWL_IO_EXCEPT)
    d->pollfd.events |= G_IO_PRI | G_IO_ERR;
  g_source_add_poll(owl_io_dispatch_source, &d->pollfd);


  other = owl_select_find_valid_io_dispatch_by_fd(fd);
  if (other)
    owl_select_invalidate_io_dispatch(other);
  owl_list_append_element(dl, d);

  return d;
}
示例#2
0
/* add a (logged-in) AIM buddy to the buddy list
 */
void owl_buddylist_add_aim_buddy(owl_buddylist *bl, const char *screenname)
{
  owl_buddy *b;
  b=g_new(owl_buddy, 1);
  
  owl_buddy_create(b, OWL_PROTOCOL_AIM, screenname);
  owl_list_append_element(&(bl->buddies), b);
}
示例#3
0
int owl_zbuddylist_adduser(owl_zbuddylist *zb, const char *name)
{
  int i, j;
  char *user;

  user=long_zuser(name);

  j=owl_list_get_size(&(zb->zusers));
  for (i=0; i<j; i++) {
    if (!strcasecmp(user, owl_list_get_element(&(zb->zusers), i))) {
      owl_free(user);
      return(-1);
    }
  }
  owl_list_append_element(&(zb->zusers), user);
  return(0);
}
示例#4
0
文件: keymap.c 项目: andersk/barnowl
/* creates and adds a key binding */
int owl_keymap_create_binding(owl_keymap *km, const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)
{
  owl_keybinding *kb, *curkb;
  int i;

  kb = owl_keybinding_new(keyseq, command, function_fn, desc);
  if (kb == NULL)
    return -1;
  /* see if another matching binding, and if so remove it.
   * otherwise just add this one. 
   */
  for (i = owl_list_get_size(&km->bindings)-1; i>=0; i--) {
    curkb = owl_list_get_element(&km->bindings, i);
    if (owl_keybinding_equal(curkb, kb)) {
      owl_list_remove_element(&km->bindings, i);
      owl_keybinding_delete(curkb);
    }
  }
  return owl_list_append_element(&km->bindings, kb);  

}
示例#5
0
文件: select.c 项目: arlynap/barnowl
/* Adds a new owl_dispatch to the list, replacing existing ones if needed. */
void owl_select_add_dispatch(owl_dispatch *d)
{
  int elt;
  owl_list *dl;

  d->needs_gc = 0;

  elt = owl_select_find_dispatch(d->fd);
  dl = owl_global_get_dispatchlist(&g);
  
  if (elt != -1) {  /* If we have a dispatch for this FD */
    owl_dispatch *d_old;
    d_old = (owl_dispatch*)owl_list_get_element(dl, elt);
    /* Ignore if we're adding the same dispatch again.  Otherwise
       replace the old dispatch. */
    if (d_old != d) {
      owl_select_remove_dispatch_at(elt);
    }
  }
  owl_list_append_element(dl, d);
}
示例#6
0
void owl_errqueue_append_err(owl_errqueue *eq, const char *msg)
{
  owl_list_append_element(&(eq->errlist), g_strdup(msg));
}