Exemplo n.º 1
0
/**
 * Create a Ewk_JS_Class to be used in @a ewk_js_object_new.
 *
 * @param meta @a Ewk_JS_Class_Meta that describes the class to be created.
 *
 * @return The Ewk_JS_Class created.
 */
Ewk_JS_Class* ewk_js_class_new(const Ewk_JS_Class_Meta* jsMetaClass)
{
    Ewk_JS_Class* cls;

    EINA_SAFETY_ON_NULL_RETURN_VAL(jsMetaClass, 0);

    cls = static_cast<Ewk_JS_Class*>(malloc(sizeof(Ewk_JS_Class)));
    if (!cls) {
        ERR("Could not allocate memory for ewk_js_class");
        return 0;
    }

    cls->meta = jsMetaClass;
    cls->default_prop = cls->meta->default_prop;

    // Don't free methods since they point to meta class methods(will be freed when meta class is freed).
    cls->methods = eina_hash_pointer_new(0);
    for (int i = 0; cls->meta->methods && cls->meta->methods[i].name; i++) {
        NPIdentifier id = _NPN_GetStringIdentifier(cls->meta->methods[i].name);
        eina_hash_add(cls->methods, id, &cls->meta->methods[i]);
    }

    // Don't free properties since they point to cls->meta class properties(will be freed when cls->meta class is freed).
    cls->properties = eina_hash_pointer_new(0);
    for (int i = 0; cls->meta->properties && cls->meta->properties[i].name; i++) {
        NPIdentifier id = _NPN_GetStringIdentifier(cls->meta->properties[i].name);
        eina_hash_add(cls->properties, id, &cls->meta->properties[i]);
    }

    return cls;
}
Exemplo n.º 2
0
int connline_plugin_trigger_callback(struct connline_context *context,
						connline_callback_f callback,
						enum connline_event event,
						char **changed_property)
{
	struct callback_trigger_data *trigger;
	Eina_Hash *context_ht;

	if (callback == NULL || context == NULL)
		return -EINVAL;

	trigger = calloc(1, sizeof(struct callback_trigger_data));
	if (trigger == NULL)
		return -ENOMEM;

	trigger->callback = callback;
	trigger->context = context;
	trigger->event = event;
	trigger->changed_property = changed_property;

	trigger->e_timer = ecore_timer_add(0, trigger_run, trigger);

	context_ht = eina_hash_find(triggers_table, context);
	if (context_ht == NULL) {
		context_ht = eina_hash_pointer_new(remove_trigger);

		eina_hash_add(triggers_table, context, context_ht);
	}

	eina_hash_add(context_ht, trigger->e_timer, trigger);

	return 0;
}
Exemplo n.º 3
0
int
enobj_add(struct enobj *eno){

	if (objdb == NULL)
		objdb = eina_hash_pointer_new(enobj_free);

	if (eno->magic != ENOBJMAGIC)
		eno->magic = ENOBJMAGIC;
	eina_hash_add(objdb, &eno->id, eno);

	return 0;
}
Exemplo n.º 4
0
static Eina_Bool
_page_populate(void *data)
{
   Page *page = data;
   const Page_Class *cls = page->cls;
   unsigned int count;

   page->od_to_list_item = eina_hash_pointer_new(NULL);

   for (count = 0; count < cls->populate_iteration_count; count++)
     {
        Elm_Genlist_Item *it;
        char letter;
        void *id, *od;
        const char **letter_str;

        if (!eina_iterator_next(page->iterator, &id)) goto end;
        // TODO: evaluate if we should keep a full copy or just store
        // fields of interest such as id, title, artist and album
        od = cls->data_from_itr(id);
        if (!od) goto end;

        it = elm_genlist_item_append
          (page->list, cls->item_cls, od,
           NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);

        letter_str = (const char **)(((char *)od) + cls->data_letter_offset);

        letter = toupper((*letter_str)[0]);
        if ((page->index) &&
            (isalpha(letter) && (page->last_index_letter[0] != letter)))
          {
             if ((page->first) && (!page->last_index_letter[0]))
               elm_index_item_append(page->index, "Special", page->first);

             page->last_index_letter[0] = letter;
             elm_index_item_append(page->index, page->last_index_letter, it);
          }
        if (!page->first) page->first = it;
        eina_hash_set(page->od_to_list_item, od, it);
        page->num_elements++;
     }

   return EINA_TRUE;

 end:
   if (cls->after_populate)
     cls->after_populate(page);

   page->populate = NULL;
   return EINA_FALSE;
}
Exemplo n.º 5
0
DBusConnection *connline_plugin_setup_event_loop(void)
{
	DBusConnection *dbus_cnx;

	dbus_cnx = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
	if (dbus_cnx == NULL)
		return NULL;

	if (setup_dbus_in_efl_mainloop(dbus_cnx) == FALSE) {
		dbus_connection_unref(dbus_cnx);
		return NULL;
	}

	if (triggers_table == NULL)
		triggers_table = eina_hash_pointer_new(
						remove_context_triggers);

	return dbus_cnx;
}
Exemplo n.º 6
0
static Ewk_JS_Object* ewk_js_npobject_to_object(NPObject* npObject)
{
    NPIdentifier* values;
    uint32_t np_props_count;
    Ewk_JS_Class* cls;
    Ewk_JS_Object* object;
    Eina_Iterator* it;
    Ewk_JS_Property* prop;
    JavaScriptObject* jso;

    if (EINA_MAGIC_CHECK(reinterpret_cast<Ewk_JS_Object*>(npObject), EWK_JS_OBJECT_MAGIC))
        return reinterpret_cast<Ewk_JS_Object*>(npObject);

    if (!_NPN_Enumerate(0, npObject, &values, &np_props_count))
        return 0;

    cls = static_cast<Ewk_JS_Class*>(malloc(sizeof(Ewk_JS_Class)));
    if (!cls) {
        ERR("Could not allocate memory for ewk_js_class");
        return 0;
    }

    cls->meta = 0;
    Ewk_JS_Default def = {
        ewk_js_npobject_property_set,
        ewk_js_npobject_property_get,
        ewk_js_npobject_property_del
    };
    cls->default_prop = def;
    cls->methods = eina_hash_pointer_new(0);
    cls->properties = eina_hash_pointer_new(reinterpret_cast<Eina_Free_Cb>(ewk_js_property_free));
    for (uint32_t i = 0; i < np_props_count; i++) {
        if (_NPN_HasProperty(0, npObject, values[i])) {
            NPVariant var;
            Ewk_JS_Property* prop = static_cast<Ewk_JS_Property*>(calloc(sizeof(Ewk_JS_Property), 1));
            if (!prop) {
                ERR("Could not allocate memory for ewk_js_property");
                goto error;
            }

            _NPN_GetProperty(0, npObject, values[i], &var);
            ewk_js_npvariant_to_variant(&(prop->value), &var);
            prop->name = _NPN_UTF8FromIdentifier(values[i]);
            eina_hash_add(cls->properties, values[i], prop);
        }
    }

    // Can't use ewk_js_object_new(cls) because it expects cls->meta to exist.
    object = static_cast<Ewk_JS_Object*>(malloc(sizeof(Ewk_JS_Object)));
    if (!object) {
        ERR("Could not allocate memory for ewk_js_object");
        goto error;
    }

    free(values);
    EINA_MAGIC_SET(object, EWK_JS_OBJECT_MAGIC);
    object->name = 0;
    object->cls = cls;
    object->view = 0;

    jso = reinterpret_cast<JavaScriptObject*>(npObject);
    if (!strcmp("Array", jso->imp->methodTable()->className(jso->imp).ascii().data()))
        object->type = EWK_JS_OBJECT_ARRAY;
    else if (!strcmp("Function", jso->imp->methodTable()->className(jso->imp).ascii().data()))
        object->type = EWK_JS_OBJECT_FUNCTION;
    else
        object->type = EWK_JS_OBJECT_OBJECT;

    if (eina_hash_population(cls->properties) < 25)
        object->properties = eina_hash_string_small_new(0);
    else
        object->properties = eina_hash_string_superfast_new(0);

    it = eina_hash_iterator_data_new(cls->properties);
    EINA_ITERATOR_FOREACH(it, prop) {
        const char* key = prop->name;
        Ewk_JS_Variant* value = &prop->value;
        eina_hash_add(object->properties, key, value);
    }

    eina_iterator_free(it);
    object->base = *reinterpret_cast<JavaScriptObject*>(npObject);

    return object;

error:
    ewk_js_class_free(cls);
    free(values);
    return 0;
}