コード例 #1
0
ファイル: emotion_webcam.c プロジェクト: tasn/efl
static Eina_Bool
_emotion_check_device(Emotion_Webcam *ew)
{
#ifdef HAVE_V4L2
   Emotion_Webcam *check;
   Eina_List *l;
   struct v4l2_capability caps;
   int fd = -1;
#endif

   if (!ew) return EINA_FALSE;
#ifdef HAVE_V4L2
   if (!ew->device) goto on_error;

   fd = open(ew->filename, O_RDONLY);
   if (fd < 0) goto on_error;

   if (ioctl(fd, VIDIOC_QUERYCAP, &caps) == -1) goto on_error;

   /* Likely not a webcam */
   if (!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE)) goto on_error;
   if (caps.capabilities & V4L2_CAP_TUNER
       || caps.capabilities & V4L2_CAP_RADIO
       || caps.capabilities & V4L2_CAP_MODULATOR)
     goto on_error;

   EINA_LIST_FOREACH(_emotion_webcams->webcams, l, check)
     if (check->device == ew->device)
       goto on_error;

   _emotion_webcams->webcams = eina_list_append(_emotion_webcams->webcams, ew);

   EINA_REFCOUNT_INIT(ew);

   if (fd >= 0) close(fd);

   return EINA_TRUE;

 on_error:
#endif
   INF("'%s' is not a webcam ['%s']", ew->name, strerror(errno));
   _emotion_webcams->webcams = eina_list_remove(_emotion_webcams->webcams, ew);
   eina_stringshare_del(ew->syspath);
   eina_stringshare_del(ew->device);
   eina_stringshare_del(ew->name);
   free(ew);
#ifdef HAVE_V4L2
   if (fd >= 0) close(fd);
#endif
   return EINA_FALSE;
}
コード例 #2
0
/**
 * @brief Create a new net object
 * @param name The name of the underlying device (eth0, br1, etc)
 * @return A newly allocated net object, or NULL on failure
 *
 * This function creates a new net object based on @p name.
 * Only the most minimal lookups are performed at creation in order
 * to save memory.
 */
Eeze_Net *
eeze_net_new(const char *name)
{
   const char *syspath = NULL;
   const char *idx;
   _udev_enumerate *en;
   _udev_list_entry *devs, *cur;
   _udev_device *device = NULL;
   Eeze_Net *net;

   net = eina_hash_find(eeze_nets, name);
   if (net)
     {
        EINA_REFCOUNT_REF(net);
        return net;
     }

   en = udev_enumerate_new(udev);
   udev_enumerate_add_match_sysname(en, name);
   udev_enumerate_add_match_subsystem(en, "net");
   udev_enumerate_scan_devices(en);
   devs = udev_enumerate_get_list_entry(en);
   udev_list_entry_foreach(cur, devs)
     {
        const char *devname, *test;

        devname = udev_list_entry_get_name(cur);
        test = strrchr(devname, '/');
        if (strcmp(++test, name)) continue;
        device = _new_device(devname);
        syspath = eina_stringshare_add(name);
        break;
     }
   if (!device) return NULL;
   net = calloc(1, sizeof(Eeze_Net));
   if (!net) return NULL;
   EINA_REFCOUNT_INIT(net);
   net->device = device;
   net->syspath = syspath;
   net->name = eina_stringshare_add(name);
   idx = udev_device_get_sysattr_value(net->device, "ifindex");
   net->index = atoi(idx);
   eina_hash_add(eeze_nets, name, net);
   udev_enumerate_unref(en);
   return net;
}
コード例 #3
0
static Etui_Provider_Instance *
_etui_provider_instance_new(const Etui_Provider_Descriptor *provider,
                            Evas                           *evas,
                            void                           *data)
{
    Etui_Provider_Instance *inst;

    inst = calloc(1, sizeof(Etui_Provider_Instance));
    EINA_SAFETY_ON_NULL_GOTO(inst, del_data);
    inst->provider = provider;
    inst->evas = evas;
    inst->data = data;

    EINA_REFCOUNT_INIT(inst);

    return inst;

  del_data:
    provider->shutdown(data);
    return NULL;
}
コード例 #4
0
ファイル: etam_packets.c プロジェクト: Limsik/e17
static Etam_Packets *
_etam_packets_new(Etam_Collection *coll, const char *name, Etam_Data_Type type)
{
   Etam_Packets *r;

   eina_rwlock_take_write(&coll->lock);
   r = eina_hash_find(coll->rows, name);
   if (r) goto end;

   r = calloc(1, sizeof (Etam_Packets));
   if (!r) return NULL;

   r->type = type;
   eina_rwlock_new(&r->lock);

   eina_hash_add(coll->rows, name, r);

   EINA_REFCOUNT_INIT(r);

 end:
   eina_rwlock_release(&coll->lock);

   return r;
}