Exemplo n.º 1
0
/**
 * @internal
 * @param desktop: The Efreet_Desktop to work with
 * @return Returns no value
 * @brief Frees the Efreet_Desktop structure and all of it's data
 */
EAPI void
efreet_desktop_free(Efreet_Desktop *desktop)
{
    if (!desktop) return;

    desktop->ref--;
    if (desktop->ref > 0) return;

    if (desktop->cached)
    {
       if (efreet_desktop_cache &&
           desktop == eina_hash_find(efreet_desktop_cache, desktop->orig_path))
       {
           eina_hash_del_by_key(efreet_desktop_cache, desktop->orig_path);
       }
       else if (old_caches)
       {
           Efreet_Old_Cache *d;
           Efreet_Desktop *curr;
           Eina_List *l;

           EINA_LIST_FOREACH(old_caches, l, d)
           {
               curr = eina_hash_find(d->desktop_cache, desktop->orig_path);
               if (curr && curr == desktop)
               {
                   eina_hash_del_by_key(d->desktop_cache, desktop->orig_path);
                   break;
               }
           }
       }
    }
Exemplo n.º 2
0
/**
 * @param ini The ini struct to work with
 * @param key The key to remove
 * @return Returns no value
 * @brief Remove the given key from the ini struct
 */
EAPI void
efreet_ini_key_unset(Efreet_Ini *ini, const char *key)
{
    if (!ini || !key || !ini->section) return;

    eina_hash_del_by_key(ini->section, key);
}
Exemplo n.º 3
0
/**
 * @param ini The Efree_Ini to work with
 * @param key The key to use
 * @param value The value to set
 * @return Returns no value
 * @brief Sets the value for the given key
 */
EAPI void
efreet_ini_string_set(Efreet_Ini *ini, const char *key, const char *value)
{
    if (!ini || !key || !ini->section) return;

    eina_hash_del_by_key(ini->section, key);
    eina_hash_add(ini->section, key, eina_stringshare_add(value));
}
Exemplo n.º 4
0
EAPI Eina_Bool
efreet_desktop_x_field_del(Efreet_Desktop *desktop, const char *key)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, EINA_FALSE);
    EINA_SAFETY_ON_TRUE_RETURN_VAL(strncmp(key, "X-", 2), EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(desktop->x, EINA_FALSE);

    return eina_hash_del_by_key(desktop->x, key);
}
Exemplo n.º 5
0
EAPI void
efreet_ini_key_unset(Efreet_Ini *ini, const char *key)
{
    EINA_SAFETY_ON_NULL_RETURN(ini);
    EINA_SAFETY_ON_NULL_RETURN(ini->section);
    EINA_SAFETY_ON_NULL_RETURN(key);

    eina_hash_del_by_key(ini->section, key);
}
EAPI void
e_config_descriptor_free(E_Config_DD *edd)
{
#if (EET_VERSION_MAJOR > 1) || (EET_VERSION_MINOR >= 8)
   eina_hash_del_by_key(config_hash, eet_data_descriptor_name_get((Eet_Data_Descriptor*)edd));
#else
   eina_hash_del_by_data(config_hash, edd);
#endif
   eet_data_descriptor_free((Eet_Data_Descriptor*)edd);
}
Exemplo n.º 7
0
EAPI void
efreet_ini_string_set(Efreet_Ini *ini, const char *key, const char *value)
{
    EINA_SAFETY_ON_NULL_RETURN(ini);
    EINA_SAFETY_ON_NULL_RETURN(ini->section);
    EINA_SAFETY_ON_NULL_RETURN(key);

    eina_hash_del_by_key(ini->section, key);
    eina_hash_add(ini->section, key, eina_stringshare_add(value));
}
Exemplo n.º 8
0
EAPI Eina_Bool
efreet_desktop_x_field_del(Efreet_Desktop *desktop, const char *key)
{
    if (!desktop || strncmp(key, "X-", 2))
        return EINA_FALSE;

    if (!desktop->x)
        return EINA_FALSE;

    return eina_hash_del_by_key(desktop->x, key);
}
Exemplo n.º 9
0
/**
 * @brief Remove a module from the server object by name
 *
 * This function removes the module of name @p from @p server.  Once a module
 * has been removed, its methods can no longer be called.
 * Note that this function only removes the module from the server's list
 * and does not actually free the module.
 * @param server The server object (NOT NULL)
 * @param name The module's name (NOT NULL)
 * @return EINA_TRUE on success or module not found, else EINA_FALSE
 */
Eina_Bool
azy_server_module_name_del(Azy_Server *server,
                           const char *name)
{
   DBG("server=%p, name=%s", server, name);
   if (!AZY_MAGIC_CHECK(server, AZY_MAGIC_SERVER))
     {
        AZY_MAGIC_FAIL(server, AZY_MAGIC_SERVER);
        return EINA_FALSE;
     }
   EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
   return eina_hash_del_by_key(server->module_defs, name);
}
Exemplo n.º 10
0
/**
 * @brief Remove a module from the server object
 *
 * This function removes @p module from @p server.  Once a module
 * has been removed, its methods can no longer be called.
 * Note that this function only removes the module from the server's list
 * and does not actually free the module.
 * @param server The server object (NOT NULL)
 * @param module The module definition (NOT NULL)
 * @return EINA_TRUE on success, else EINA_FALSE
 */
Eina_Bool
azy_server_module_del(Azy_Server *server,
                      Azy_Server_Module_Def *module)
{
   DBG("server=%p, module=%p", server, module);
   if (!AZY_MAGIC_CHECK(server, AZY_MAGIC_SERVER))
     {
        AZY_MAGIC_FAIL(server, AZY_MAGIC_SERVER);
        return EINA_FALSE;
     }
   EINA_SAFETY_ON_NULL_RETURN_VAL(module, EINA_FALSE);
   return eina_hash_del_by_key(server->module_defs, module->name);
}
Exemplo n.º 11
0
/**
 * @param desktop: The desktop file to save
 * @param file: The filename to save as
 * @return Returns 1 on success or 0 on failure
 * @brief Saves @a desktop to @a file
 */
EAPI int
efreet_desktop_save_as(Efreet_Desktop *desktop, const char *file)
{
    if (desktop->cached && efreet_desktop_cache &&
        desktop == eina_hash_find(efreet_desktop_cache, desktop->orig_path))
    {
        desktop->cached = 0;
        eina_hash_del_by_key(efreet_desktop_cache, desktop->orig_path);
    }
    FREE(desktop->orig_path);
    desktop->orig_path = strdup(file);
    return efreet_desktop_save(desktop);
}
Exemplo n.º 12
0
EAPI Eina_Bool
efreet_desktop_x_field_set(Efreet_Desktop *desktop, const char *key, const char *data)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, EINA_FALSE);
    EINA_SAFETY_ON_TRUE_RETURN_VAL(strncmp(key, "X-", 2), EINA_FALSE);

    if (!desktop->x)
        desktop->x = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));

    eina_hash_del_by_key(desktop->x, key);
    eina_hash_add(desktop->x, key, eina_stringshare_add(data));

    return EINA_TRUE;
}
Exemplo n.º 13
0
/**
 * @param file: The file to get the Efreet_Desktop from
 * @return Returns a reference to a cached Efreet_Desktop on success, NULL
 * on failure. This reference should not be freed.
 * @brief Gets a reference to an Efreet_Desktop structure representing the
 * contents of @a file or NULL if @a file is not a valid .desktop file.
 *
 * By using efreet_desktop_get the Efreet_Desktop will be saved in an internal
 * cache, and changes will be signalled by events.
 *
 * Efreet will also try to save all files fetched by efreet_desktop_get in a
 * cache to speed up further requests.
 */
EAPI Efreet_Desktop *
efreet_desktop_get(const char *file)
{
    /* TODO: Check if we need to differentiate between desktop_new and desktop_get */
    Efreet_Desktop *desktop;

    if (!file) return NULL;
    if (efreet_desktop_cache)
    {
        char rp[PATH_MAX];

        if (!realpath(file, rp)) return NULL;
        desktop = eina_hash_find(efreet_desktop_cache, rp);
        if (desktop)
        {
            if (efreet_desktop_cache_check(desktop))
            {
                desktop->ref++;
                return desktop;
            }

            desktop->cached = 0;
            eina_hash_del_by_key(efreet_desktop_cache, rp);
        }
    }

    desktop = efreet_desktop_new(file);
    if (!desktop) return NULL;

    if (!desktop->eet)
    {
        char buf[PATH_MAX];
        char *p;

        /*
         * Read file from disk, save path in cache so it will be included in next
         * cache update
         */
        strncpy(buf, desktop->orig_path, PATH_MAX);
        buf[PATH_MAX - 1] = '\0';
        p = dirname(buf);
        if (!eina_list_search_unsorted(efreet_desktop_dirs, EINA_COMPARE_CB(strcmp), p))
            efreet_desktop_dirs = eina_list_append(efreet_desktop_dirs, eina_stringshare_add(p));
        efreet_desktop_update_cache();
    }

    if (efreet_desktop_cache) eina_hash_add(efreet_desktop_cache, desktop->orig_path, desktop);
    desktop->cached = 1;
    return desktop;
}
Exemplo n.º 14
0
EAPI Eina_Bool
efreet_desktop_x_field_set(Efreet_Desktop *desktop, const char *key, const char *data)
{
    if (!desktop || strncmp(key, "X-", 2))
        return EINA_FALSE;

    if (!desktop->x)
        desktop->x = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));

    eina_hash_del_by_key(desktop->x, key);
    eina_hash_add(desktop->x, key, eina_stringshare_add(data));

    return EINA_TRUE;
}
Exemplo n.º 15
0
void clean_inexistant_files(Eina_Hash *map_histo)
{
    struct stat st;
    Eina_Iterator *iter = eina_hash_iterator_data_new(map_histo);
    void **data = malloc(sizeof(void**));
    list_t *to_delete = NULL;
    while(eina_iterator_next(iter, data)) {
        histogram_t *current = *data;
        if(stat(current->file, &st) != 0) {
            to_delete = list_append(to_delete, current->file);
        }
    }
    eina_iterator_free(iter);

    list_t *current = to_delete;
    while(current) {
        printf("Deleting cache for %s\n", current->value);
        eina_hash_del_by_key(map_histo, current->value);
        current = current->next;
    }
}
Exemplo n.º 16
0
/**
 * @internal
 * @param file The file to parse
 * @return Returns an Eina_Hash with the contents of @a file, or NULL if the
 *         file fails to parse or if the file doesn't exist
 * @brief Parses the ini file @a file into an Eina_Hash
 */
static Eina_Hash *
efreet_ini_parse(const char *file)
{
    const char *buffer, *line_start;
    FILE *f;
    Eina_Hash *data, *section = NULL;
    struct stat file_stat;
    int line_length, left;

    if (!file) return NULL;

    f = fopen(file, "rb");
    if (!f) return NULL;

    if (fstat(fileno(f), &file_stat) || (file_stat.st_size < 1))
    {
        fclose(f);
        return NULL;
    }
    if (!S_ISREG(file_stat.st_mode)) /* if not a regular file - close */
    {
        fclose(f);
        return NULL;
    }

    left = file_stat.st_size;
    buffer = mmap(NULL, left, PROT_READ, MAP_SHARED, fileno(f), 0);
    if (buffer == MAP_FAILED)
    {
        fclose(f);
        return NULL;
    }

    data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free));

    line_start = buffer;
    while (left > 0)
    {
        int sep;

        /* find the end of line */
        for (line_length = 0;
                (line_length < left) &&
                (line_start[line_length] != '\n'); line_length++)
            ;

        /* check for all white space */
        while (isspace(line_start[0]) && (line_length > 0))
        {
            line_start++;
            line_length--;
        }

        /* skip empty lines and comments */
        if ((line_length == 0) || (line_start[0] == '\r') ||
                (line_start[0] == '\n') || (line_start[0] == '#') ||
                (line_start[0] == '\0'))
            goto next_line;

        /* new section */
        if (line_start[0] == '[')
        {
            int header_length;

            /* find the ']' */
            for (header_length = 1;
                    (header_length < line_length) &&
                    (line_start[header_length] != ']'); ++header_length)
                ;

            if (line_start[header_length] == ']')
            {
                const char *header;

                header = alloca(header_length * sizeof(unsigned char));
                if (!header) goto next_line;

                memcpy((char*)header, line_start + 1, header_length - 1);
                ((char*)header)[header_length - 1] = '\0';

                section = eina_hash_string_small_new(EINA_FREE_CB(eina_stringshare_del));

                eina_hash_del_by_key(data, header);
//                if (old) INF("[efreet] Warning: duplicate section '%s' "
  //                              "in file '%s'", header, file);

                eina_hash_add(data, header, section);
            }
            else
            {
                /* invalid file - skip line? or refuse to parse file? */
                /* just printf for now till we figure out what to do */
//                printf("Invalid file (%s) (missing ] on group name)\n", file);
            }
            goto next_line;
        }

        if (!section)
        {
//            INF("Invalid file (%s) (missing section)", file);
            goto next_line;
        }

        /* find for '=' */
        for (sep = 0; (sep < line_length) && (line_start[sep] != '='); ++sep)
            ;

        if (sep < line_length)
        {
            char *key, *value;
            int key_end, value_start, value_end;

            /* trim whitespace from end of key */
            for (key_end = sep - 1;
                    (key_end > 0) && isspace(line_start[key_end]); --key_end)
                ;

            if (!isspace(line_start[key_end])) key_end++;

            /* trim whitespace from start of value */
            for (value_start = sep + 1;
                 (value_start < line_length) &&
                 isspace(line_start[value_start]); ++value_start)
                ;

            /* trim \n off of end of value */
            for (value_end = line_length;
                 (value_end > value_start) &&
                 ((line_start[value_end] == '\n') ||
                  (line_start[value_end] == '\r')); --value_end)
                ;

            if (line_start[value_end] != '\n'
                    && line_start[value_end] != '\r'
                    && value_end < line_length)
                value_end++;

            /* make sure we have a key. blank values are allowed */
            if (key_end == 0)
            {
                /* invalid file... */
//                INF("Invalid file (%s) (invalid key=value pair)", file);

                goto next_line;
            }

            key = alloca(key_end + 1);
            value = alloca(value_end - value_start + 1);
            if (!key || !value) goto next_line;

            memcpy(key, line_start, key_end);
            key[key_end] = '\0';

            memcpy(value, line_start + value_start,
                    value_end - value_start);
            value[value_end - value_start] = '\0';

            eina_hash_del_by_key(section, key);
            eina_hash_add(section, key, efreet_ini_unescape(value));
        }
//        else
//        {
//            /* invalid file... */
//            INF("Invalid file (%s) (missing = from key=value pair)", file);
//        }

next_line:
        left -= line_length + 1;
        line_start += line_length + 1;
    }
    munmap((char*) buffer, file_stat.st_size);
    fclose(f);

#if 0
    if (!eina_hash_population(data))
    {
        eina_hash_free(data);
        return NULL;
    }
#endif
    return data;
}
Exemplo n.º 17
0
void
esql_event_error(Esql *e)
{
   Esql *ev;

   DBG("(e=%p)", e);
   ev = e->pool_member ? (Esql *)e->pool_struct : e; /* use pool struct for events */
   e->error = e->backend.error_get(e);
   e->query_end = ecore_time_get();
   if (e->pool_member)
     {
        e->pool_struct->error = e->error;
        e->pool_struct->cur_query = e->cur_query;
        e->pool_struct->cur_id = e->cur_id;
     }
   if (e->current == ESQL_CONNECT_TYPE_QUERY)
     {
        Esql_Query_Cb qcb;

        qcb = eina_hash_find(esql_query_callbacks, &e->cur_id);
        if (qcb)
          {
             Esql_Res *res;

             res = esql_res_calloc(1);
             EINA_SAFETY_ON_NULL_RETURN(res);
             res->refcount = 1;
             res->e = ev;
             res->data = e->cur_data;
             res->qid = e->cur_id;
             ev->res = res;
             res->query = e->cur_query;
             e->cur_query = NULL;

             res->error = e->error;
             e->error = NULL;
             if (e->pool_member)
               ERR("Pool member %u: Connection error: %s", e->pool_id, res->error);
             else
               ERR("Connection error: %s", res->error);

             INFO("Executing callback for current query (%u)", res->qid);
             qcb(res, e->cur_data);

             e->query_start = e->query_end = 0.0;
             eina_hash_del_by_key(esql_query_callbacks, &e->cur_id);
             esql_res_free(NULL, res);
          }
        if (!ecore_main_fd_handler_active_get(e->fdh, ECORE_FD_ERROR))
          {
             esql_next(e);
             return;
          }
     }
   else
     {
        if (ev->connect_cb)
          ev->connect_cb(ev, ev->connect_cb_data);
     }
   ecore_event_add(ESQL_EVENT_ERROR, ev, (Ecore_End_Cb)esql_fake_free, NULL);
   e->event_count++;

   esql_disconnect(e);
   if (e->reconnect) e->reconnect_timer = ecore_timer_add(1.0, (Ecore_Task_Cb)esql_reconnect_handler, e);
}
Exemplo n.º 18
0
/**
 * @internal
 * @param file The file to parse
 * @return Returns an Eina_Hash with the contents of @a file, or NULL if the
 *         file fails to parse or if the file doesn't exist
 * @brief Parses the ini file @a file into an Eina_Hash
 */
static Eina_Hash *
efreet_ini_parse(const char *file)
{
    Eina_Hash *data = NULL, *section = NULL;
    Eina_Iterator *it = NULL;
    Eina_File_Line *line;
    Eina_File *f;

    EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
    f = eina_file_open(file, EINA_FALSE);
    if (!f)
        return NULL;

    data = eina_hash_string_small_new(EINA_FREE_CB(eina_hash_free));
    if (!data) goto error;

    /* let's make mmap safe and just get 0 pages for IO erro */
    eina_mmap_safety_enabled_set(EINA_TRUE);

    it = eina_file_map_lines(f);
    if (!it) goto error;
    EINA_ITERATOR_FOREACH(it, line)
    {
        const char *eq;
        unsigned int start = 0;

        /* skip empty lines */
        if (line->length == 0) continue;
        /* skip white space at start of line */
        while ((start < line->length) && (isspace((unsigned char)line->start[start])))
            start++;
        /* skip empty lines */
        if (start == line->length) continue;
        /* skip comments */
        if (line->start[start] == '#') continue;

        /* new section */
        if (line->start[start] == '[')
        {
            const char *head_start;
            const char *head_end;

            head_start = &(line->start[start]) + 1;
            head_end = memchr(line->start, ']', line->length);

            if (head_end)
            {
                char *header;
                size_t len;

                len = head_end - head_start + 1;
                header = alloca(len);

                memcpy(header, head_start, len - 1);
                header[len - 1] = '\0';

                section = eina_hash_string_small_new(EINA_FREE_CB(eina_stringshare_del));

                eina_hash_del_by_key(data, header);
                eina_hash_add(data, header, section);
            }
            else
            {
                /* invalid file - skip line? or refuse to parse file? */
                /* just printf for now till we figure out what to do */
//                ERR("Invalid file (%s) (missing ] on group name)", file);
            }
            continue;
        }

        if (!section)
        {
            INF("Invalid file (%s) (missing section)", file);
            goto error;
        }

        eq = memchr(line->start, '=', line->length);

        if (eq)
        {
            const char *key_start, *key_end;
            const char *value_start, *value_end;
            char *key, *value;
            size_t len;

            key_start = &(line->start[start]);
            key_end = eq - 1;

            /* trim whitespace from end of key */
            while ((isspace((unsigned char)*key_end)) && (key_end > key_start))
                key_end--;
            key_end++;

            /* make sure we have a key */
            if (key_start == key_end) continue;

            value_start = eq + 1;
            value_end = line->end;

            /* line->end points to char after '\n' or '\r' */
            value_end--;
            /* trim whitespace from end of value */
            while ((isspace((unsigned char)*value_end)) && (value_end > value_start))
                value_end--;
            value_end++;

            /* trim whitespace from start of value */
            while ((isspace((unsigned char)*value_start)) && (value_start < value_end))
                value_start++;

            len = key_end - key_start + 1;
            key = alloca(len);

            memcpy(key, key_start, len - 1);
            key[len - 1] = '\0';

            /* empty value allowed */
            if (value_end == value_start)
            {
                eina_hash_del_by_key(section, key);
                eina_hash_add(section, key, "");
            }
            else
            {
                len = value_end - value_start + 1;
                value = alloca(len);
                memcpy(value, value_start, len - 1);
                value[len - 1] = '\0';

                eina_hash_del_by_key(section, key);
                eina_hash_add(section, key, efreet_ini_unescape(value));
            }
        }
        else
        {
            /* invalid file... */
            INF("Invalid file (%s) (missing = from key=value pair)", file);
            goto error;
        }
    }
    eina_iterator_free(it);
    eina_file_close(f);

#if 0
    if (!eina_hash_population(data))
    {
        eina_hash_free(data);
        return NULL;
    }
#endif
    return data;
error:
    if (data) eina_hash_free(data);
    if (it) eina_iterator_free(it);

    eina_file_close(f);
    return NULL;
}
Exemplo n.º 19
0
static void
esql_next(Esql *e)
{
   Esql_Set_Cb cb;

   e->current = ESQL_CONNECT_TYPE_NONE;
   if (!e->backend_set_funcs)
     {
        if (e->pool_member)
          {
             if (!esql_pool_rebalance(e->pool_struct, e))
               {
                  INFO("Pool member %u is now idle", e->pool_id);
                  return;
               }
          }
        else
          {
             INFO("No calls queued");
             return;
          }
     }
   /* next call */
   cb = e->backend_set_funcs->data;
   if (cb == (Esql_Set_Cb)esql_database_set)
     {
        cb(e, e->backend_set_params->data);
        UPDATE_LISTS(database_set);
        if (e->pool_member)
          INFO("Pool member %u: next call: DB change", e->pool_id);
        else
          INFO("Next call: DB change");
     }
   else if (cb == (Esql_Set_Cb)esql_query)
     { /* don't use cb, leads to unnecessary calls and breakage */
        void *data;

        data = eina_hash_find(esql_query_data, &e->backend_ids->data);
        DBG("(e=%p, query=\"%s\")", e, (char*)e->backend_set_params->data);
        e->query_start = ecore_time_get();
        e->backend.query(e, e->backend_set_params->data, strlen((char*)e->backend_set_params->data));
        e->current = ESQL_CONNECT_TYPE_QUERY;
        e->cur_data = data;
        e->cur_id = (Esql_Query_Id)((uintptr_t)e->backend_ids->data);
        e->cur_query = e->backend_set_params->data;
        e->backend_set_params->data = NULL;
        if (data) eina_hash_del_by_key(esql_query_data, &e->backend_ids->data);
        UPDATE_LISTS(query);
        if (e->pool_member)
          INFO("Pool member %u: next call: query", e->pool_id);
        else
          INFO("Next call: query");
        e->error = e->backend.error_get(e);
        if (e->error)
          {
             ERR("%s", e->error);
             esql_event_error(e);
             return;
          }
     }
   esql_connect_handler(e, e->fdh); /* have to call again to start next call */
}
Exemplo n.º 20
0
void
esql_call_complete(Esql *e)
{
   Esql *ev;

   DBG("(e=%p)", e);
   ev = e->pool_member ? (Esql *)e->pool_struct : e;
   switch (e->current)
     {
      case ESQL_CONNECT_TYPE_INIT:
        e->connected = EINA_TRUE;
        if (e->pool_member)
          {
             e->pool_struct->e_connected++;
             INFO("Pool connection %u created (%d/%d)", e->pool_id, e->pool_struct->e_connected, e->pool_struct->size);
          }
        else
          INFO("Connected");

        if ((!e->pool_member) || (e->pool_member && (!e->pool_struct->connected) && (e->pool_struct->e_connected == e->pool_struct->size)))
          {
             if (e->pool_member)
               {
                  e->pool_struct->connected = EINA_TRUE;
                  INFO("[%d/%d] connections made for pool", e->pool_struct->size, e->pool_struct->size);
               }
             if (ev->connect_cb)
               ev->connect_cb(ev, ev->connect_cb_data);
             else
               {
                  ecore_event_add(ESQL_EVENT_CONNECT, ev, (Ecore_End_Cb)esql_fake_free, NULL);
                  e->event_count++;
               }
          }
        break;

      case ESQL_CONNECT_TYPE_DATABASE_SET:
        if (e->pool_member)
          INFO("Pool member %u: working database is now '%s'", e->pool_id, e->database);
        else
          INFO("Working database is now '%s'", e->database);
        break;

      case ESQL_CONNECT_TYPE_QUERY:
        DBG("(ev=%p, qid=%u)", ev, e->cur_id);
        e->query_end = ecore_time_get();
        {
           Esql_Res *res;
           Esql_Query_Cb qcb;

           if (e->res)
             res = e->res;
           else
             {
                res = esql_res_calloc(1);
                EINA_SAFETY_ON_NULL_GOTO(res, out);
                res->e = e;
                e->backend.res(res);
             }
           ev->res = res;
           res->e = ev;
           res->refcount = 1;
           res->query = e->cur_query;
           e->cur_query = NULL;
           res->data = e->cur_data;
           res->qid = e->cur_id;
           qcb = eina_hash_find(esql_query_callbacks, &e->cur_id);
           if (qcb)
             {
                INFO("Executing callback for current query (%u)", res->qid);
                qcb(res, e->cur_data);
                e->query_start = e->query_end = 0.0;
                eina_hash_del_by_key(esql_query_callbacks, &e->cur_id);
                esql_res_free(NULL, res);
             }
           else
             {
                INFO("Emitting event for current query (%u)", res->qid);
                ecore_event_add(ESQL_EVENT_RESULT, res, (Ecore_End_Cb)esql_res_free, NULL);
             }
           e->res = ev->res = NULL;
        }
        break;

      default:
        break;
     }
out:
   esql_next(e);
}
Exemplo n.º 21
0
Arquivo: eina.c Projeto: fd00/borghen
void borghen_backend_remove(BorghenObject hash, BorghenObject key)
{
  eina_hash_del_by_key(hash, key);
}
Exemplo n.º 22
0
Arquivo: zrpcdb.c Projeto: zmike/ezrpc
void
event_cb(Esql_Res *res, Zentific_Ctx *ctx){
	const char *query;
	Z_Ctx_Cb end_cb;
	Zrpcdb_Cb cb;
	Esql_Query_Id qid;
	long long int insert_id;
	DB *db;
	Eina_Bool state;

	qid = esql_res_query_id_get(res);
	state = ctx->state;
	ctx->state = EINA_FALSE;
	if (esql_res_error_get(res)){
		ERR("Query %lu: \"%s\" - %s", qid, esql_res_query_get(res), esql_res_error_get(res));
		eina_hash_del_by_key(db_cbs, &qid);
		ctx->error = AZY_ERR(DB_QUERY);
		ecore_event_add(ZRPCDB_EVENT_ERROR, ctx, fake_free, NULL);
		return;
	}
	query = esql_res_query_get(res);
	cb = eina_hash_find(type_cbs, &qid);
	db = esql_data_get(esql_res_esql_get(res));
	if (cb) { /* all SELECT calls have cbs */
		DBG("%i rows returned", esql_res_rows_count(res));
		if (state && (esql_res_rows_count(res) > 1)){
			ctx->error = AZY_ERR(DB_MULTI);
			eina_hash_del_by_key(db_cbs, &qid);
			ctx->state = state;
			ecore_event_add(ZRPCDB_EVENT_ERROR, ctx, fake_free, NULL);
			return;
		}
		end_cb = eina_hash_find(db_cbs, &qid); /* another db call queued */
		if (end_cb) {
			eina_hash_del_by_key(db_cbs, &qid);
			end_cb(res, ctx, cb(res));
			return;
		}
		if (ctx->cbs){
			end_cb = ctx->cbs->data;
			end_cb(ctx, cb(res));
		} else {
			ctx->state = state;
			ctx->retval = cb(res);
			ecore_event_add(ZRPCDB_EVENT_RESULT, ctx, fake_free, NULL);
		}
		return;
	}
	end_cb = eina_hash_find(db_cbs, &qid); /* another db call queued */
	insert_id = esql_res_id(res);
	if (esql_res_rows_affected(res))
		INF("Query \"%s\" inserted with id %lli", esql_res_query_get(res), insert_id);
	else
		ERR("Query \"%s\" affected 0 rows", esql_res_query_get(res));
	if (end_cb) {
		eina_hash_del_by_key(db_cbs, &qid);
		if (state) end_cb(res, ctx, insert_id);
		else end_cb(res, ctx);
		return;
	}
	if (ctx->cbs) {
		end_cb = ctx->cbs->data;
		if (state) end_cb(ctx, insert_id);
		else end_cb(ctx);
	} else {
		ctx->state = state;
		ctx->retval = (intptr_t*)(int)insert_id;
		ecore_event_add(ZRPCDB_EVENT_RESULT, ctx, fake_free, NULL);
	}
}