Exemple #1
0
Eina_Bool
_elm_web_init(const char *engine)
{
   char buf[PATH_MAX];

     if (!bs_mod_get(buf, sizeof(buf), "elementary/web", engine))
       snprintf(buf, sizeof(buf),
                "%s/elementary/modules/web/%s/%s/module"EFL_SHARED_EXTENSION,
                _elm_lib_dir, engine, MODULE_ARCH);

   if (ewm.m)
     {
        // Check if the module is already open
        if (!strcmp(buf, eina_module_file_get(ewm.m)))
          return EINA_TRUE;

        // We are leaking reference on purpose here, as we can't be sure that
        // the web engine is not leaking state around preventing a clean exit.
        // Only future elm_web object created from now will use the new engine.
        ewm.unneed_web = NULL;
        ewm.need_web = NULL;
        ewm.window_features_ref = NULL;
        ewm.window_features_unref = NULL;
        ewm.window_features_property_get = NULL;
        ewm.window_features_region_get = NULL;
        ewm.class_get = NULL;
     }

   ewm.m = eina_module_new(buf);
   if (!ewm.m) return EINA_FALSE;

   if (!eina_module_load(ewm.m))
     {
        eina_module_free(ewm.m);
        ewm.m = NULL;
        return EINA_FALSE;
     }

   ewm.unneed_web = eina_module_symbol_get(ewm.m, "ewm_unneed_web");
   ewm.need_web = eina_module_symbol_get(ewm.m, "ewm_need_web");
   ewm.window_features_ref = eina_module_symbol_get(ewm.m, "ewm_window_features_ref");
   ewm.window_features_unref = eina_module_symbol_get(ewm.m, "ewm_window_features_unref");
   ewm.window_features_property_get = eina_module_symbol_get(ewm.m, "ewm_window_features_property_get");
   ewm.window_features_region_get = eina_module_symbol_get(ewm.m, "ewm_window_features_region_get");
   ewm.class_get = eina_module_symbol_get(ewm.m, "ewm_class_get");

   // Only the class_get is mandatory
   if (!ewm.class_get) return EINA_FALSE;
   return EINA_TRUE;
}
int main(int c, char **v)
{
   int wfd, rfd;
   Slave_Command cmd;
   void *params = NULL;
   Eina_Module *m;
   Eina_Bool quit = EINA_FALSE;

   if (c < 3)
     return 1;

   eina_init();

   loaders = eina_hash_string_superfast_new(NULL);

   wfd = atoi(v[1]);
   rfd = atoi(v[2]);

   while (!quit)
     {
        if (!command_read(rfd, &cmd, &params))
          {
             error_send(wfd, CSERVE2_INVALID_COMMAND);
             return 1;
          }
        switch (cmd)
          {
           case IMAGE_OPEN:
              handle_image_open(wfd, params);
              break;
           case IMAGE_LOAD:
              handle_image_load(wfd, params);
              break;
           case SLAVE_QUIT:
              quit = EINA_TRUE;
              break;
           default:
              error_send(wfd, CSERVE2_INVALID_COMMAND);
          }
     }

   eina_hash_free(loaders);

   EINA_LIST_FREE(modules, m)
      eina_module_free(m);

   eina_shutdown();

   return 0;
}
Exemple #3
0
Eina_Module *
_ecore_evas_engine_load(const char *engine)
{
   const char *path;
   Eina_List *l;
   Eina_Module *em = NULL;
   Eina_Bool run_in_tree;

   EINA_SAFETY_ON_NULL_RETURN_VAL(engine, NULL);

   em =  (Eina_Module *)eina_hash_find(_registered_engines, engine);
   if (em) return em;

   run_in_tree = !!getenv("EFL_RUN_IN_TREE");

   EINA_LIST_FOREACH(_engines_paths, l, path)
     {
        char tmp[PATH_MAX] = "";

#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
        if (getuid() == geteuid())
#endif
          {
             if (run_in_tree)
               {
                  struct stat st;
                  snprintf(tmp, sizeof(tmp), "%s/%s/.libs/%s",
                           path, engine, ECORE_EVAS_ENGINE_NAME);
                  if (stat(tmp, &st) != 0)
                  tmp[0] = '\0';
               }
          }

        if (tmp[0] == '\0')
          snprintf(tmp, sizeof(tmp), "%s/%s/%s/%s",
                   path, engine, MODULE_ARCH, ECORE_EVAS_ENGINE_NAME);

        em = eina_module_new(tmp);
        if (!em) continue;

        if (!eina_module_load(em))
          {
             eina_module_free(em);
             continue;
          }
        if (eina_hash_add(_registered_engines, engine, em))
          return em;
     }
Exemple #4
0
void
_elm_module_unload(Elm_Module *m)
{
   eina_stringshare_del(m->so_path);
   eina_stringshare_del(m->data_dir);
   eina_stringshare_del(m->bin_dir);
   ELM_SAFE_FREE(m->api, free);
   if (m->module)
     {
        if (m->shutdown_func) m->shutdown_func(m);
        eina_module_unload(m->module);
        eina_module_free(m->module);
        m->module = NULL;
     }
   m->shutdown_func = NULL;
   m->init_func = NULL;
}
/**
 * @brief Free the given #Azy_Server_Module_Def
 *
 * This function frees the given #Azy_Server_Module_Def, and should only
 * be called after the module will no longer be used.
 * @param def The #Azy_Server_Module_Def to free
 */
void
azy_server_module_def_free(Azy_Server_Module_Def *def)
{
   if (!def) return;
   if (!AZY_MAGIC_CHECK(def, AZY_MAGIC_SERVER_MODULE_DEF))
     {
        AZY_MAGIC_FAIL(def, AZY_MAGIC_SERVER_MODULE_DEF);
        return;
     }

   eina_stringshare_del(def->name);
   eina_hash_free(def->methods);
   if (def->module) eina_module_free(def->module);

   AZY_MAGIC_SET(def, AZY_MAGIC_NONE);
   free(def);
}
Exemple #6
0
Eina_Module *
_edje_module_handle_load(const char *module)
{
   const char *path;
   Eina_List *l;
   Eina_Module *em = NULL;
   Eina_Bool run_in_tree;

   EINA_SAFETY_ON_NULL_RETURN_VAL(module, NULL);

   em =  (Eina_Module *)eina_hash_find(_registered_modules, module);
   if (em) return em;

   run_in_tree = !!getenv("EFL_RUN_IN_TREE");

   EINA_LIST_FOREACH(_modules_paths, l, path)
     {
        char tmp[PATH_MAX] = "";

        if (run_in_tree)
          {
             struct stat st;
             snprintf(tmp, sizeof(tmp), "%s/%s/.libs/%s",
                      path, module, EDJE_MODULE_NAME);
             if (stat(tmp, &st) != 0)
               tmp[0] = '\0';
          }

        if (tmp[0] == '\0')
          snprintf(tmp, sizeof(tmp), "%s/%s/%s/%s",
                   path, module, MODULE_ARCH, EDJE_MODULE_NAME);

        em = eina_module_new(tmp);
        if (!em) continue;

        if (!eina_module_load(em))
          {
             eina_module_free(em);
             continue;
          }
        if (eina_hash_add(_registered_modules, module, em))
          return em;
     }
/**
 * @brief Load a library and run a function from it which returns an #Azy_Server_Module_Def
 * This function loads @p file as an Eina_Module. If @p modname is specified, it attempts to call
 * modname() from the loaded module to create an #Azy_Server_Module_Def. If @p is NULL, the following
 * shell script formula will be used to generate a function name:
 * shell$ echo "$(basename $file | cut -d'.' -f1)_module_def"
 * @param file The file to load as a module (NOT NULL)
 * @param modname The name of the function to call of type #Azy_Server_Module_Def_Cb
 * @return On success, the loaded #Azy_Server_Module_Def, else NULL.
 */
Azy_Server_Module_Def *
azy_server_module_def_load(const char *file,
                           const char *modname)
{
   Eina_Module *m;
   Azy_Server_Module_Def *ret;
   const char *name;
   char buf[4096];
   Azy_Server_Module_Def_Cb cb;

   EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);

   if (modname) name = modname;
   else /* attempt to autodetect module name */
     {
        const char *s, *d;

        s = strrchr(file, '/');
        EINA_SAFETY_ON_NULL_RETURN_VAL(s, NULL);

        d = strchr(++s, '.');
        EINA_SAFETY_ON_NULL_RETURN_VAL(d, NULL);
        EINA_SAFETY_ON_TRUE_RETURN_VAL(d - s + sizeof("_module_def") > sizeof(buf), NULL);
        snprintf(buf, d - s + sizeof("_module_def"), "%s_module_def", s);
        name = buf;
     }

   m = eina_module_new(file);
   EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);

   EINA_SAFETY_ON_TRUE_GOTO(!eina_module_load(m), err);
   cb = (Azy_Server_Module_Def_Cb)eina_module_symbol_get(m, name);
   EINA_SAFETY_ON_TRUE_GOTO(!cb, err);
   ret = cb();
   EINA_SAFETY_ON_TRUE_GOTO(!ret, err);
   ret->module = m;
   return ret;

err:
   eina_module_free(m);
   return NULL;
}
bool InjectedBundle::initialize(const WebProcessCreationParameters&, API::Object* initializationUserData)
{
    m_platformBundle = eina_module_new(m_path.utf8().data());
    if (!m_platformBundle) {
        EINA_LOG_CRIT("Error loading the injected bundle: eina_module_new() failed");
        return false;
    }
    if (!eina_module_load(m_platformBundle)) {
        EINA_LOG_CRIT("Error loading the injected bundle from %s: %s", m_path.utf8().data(), eina_error_msg_get(eina_error_get()));
        eina_module_free(m_platformBundle);
        m_platformBundle = 0;
        return false;
    }

    WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(eina_module_symbol_get(m_platformBundle, "WKBundleInitialize"));
    if (!initializeFunction) {
        EINA_LOG_CRIT("Error loading WKBundleInitialize symbol from injected bundle.");
        return false;
    }

    initializeFunction(toAPI(this), toAPI(initializationUserData));
    return true;
}
Exemple #9
0
static Eina_Bool
_c_init(void)
{
   long ms = 0;

   if (_c) return EINA_TRUE;
   if (_c_fail) return EINA_FALSE;
   _c = calloc(1, sizeof(Ecore_Con_Curl));
   if (!_c) goto error;

#define LOAD(x)                               \
  if (!_c->mod) {                             \
       if ((_c->mod = eina_module_new(x))) {  \
            if (!eina_module_load(_c->mod)) { \
                 eina_module_free(_c->mod);   \
                 _c->mod = NULL;              \
              }                               \
         }                                    \
    }
#if defined(_WIN32) || defined(__CYGWIN__)
   LOAD("libcurl-4.dll"); // try correct dll first
   LOAD("libcurl.dll"); // try 1
   LOAD("curllib.dll"); // if fail try 2
#elif defined(__APPLE__) && defined(__MACH__)
   LOAD("libcurl.4.dylib"); // try 1
   LOAD("libcurl.so.4"); // if fail try 2
#else
   LOAD("libcurl.so.4"); // try only
#endif
   if (!_c->mod) goto error;

#define SYM(x) if (!(_c->x = eina_module_symbol_get(_c->mod, #x))) \
    goto error
   SYM(curl_global_init);
   SYM(curl_global_cleanup);
   SYM(curl_multi_init);
   SYM(curl_multi_timeout);
   SYM(curl_multi_cleanup);
   SYM(curl_multi_remove_handle);
   SYM(curl_multi_strerror);
   SYM(curl_multi_info_read);
   SYM(curl_multi_fdset);
   SYM(curl_multi_perform);
   SYM(curl_multi_add_handle);
   SYM(curl_multi_setopt);
   SYM(curl_easy_init);
   SYM(curl_easy_setopt);
   SYM(curl_easy_strerror);
   SYM(curl_easy_cleanup);
   SYM(curl_easy_getinfo);
   SYM(curl_slist_free_all);
   SYM(curl_slist_append);
   SYM(curl_version_info);

   // curl_global_init() is not thread safe!
   if (_c->curl_global_init(CURL_GLOBAL_ALL)) goto error;
   _c->_curlm = _c->curl_multi_init();
   if (!_c->_curlm)
     {
        _c->curl_global_cleanup();
        goto error;
     }
   _c->curl_multi_timeout(_c->_curlm, &ms);
   if ((ms >= CURL_MIN_TIMEOUT) || (ms <= 0)) ms = CURL_MIN_TIMEOUT;
   _curl_timer = ecore_timer_add((double)ms / 1000.0,
                                 _ecore_con_url_timer, NULL);
   ecore_timer_freeze(_curl_timer);
   return EINA_TRUE;
error:
   if (_c)
     {
        if (_c->mod) eina_module_free(_c->mod);
        free(_c);
        _c = NULL;
     }
   _c_fail = EINA_TRUE;
   return EINA_FALSE;
}
Exemple #10
0
Eina_Bool
_elm_module_load(Elm_Module *m)
{
   const char *home;
   char buf[PATH_MAX];

   if (m->module) return EINA_TRUE;

   home = getenv("HOME");
   if (home)
     {
        snprintf(buf, sizeof(buf), "%s/"ELEMENTARY_BASE_DIR"/modules/%s/%s/module" EFL_SHARED_EXTENSION, home, m->name, MODULE_ARCH);
        m->module = eina_module_new(buf);
        if (m->module && eina_module_load (m->module) == EINA_TRUE)
          {
             m->init_func = eina_module_symbol_get(m->module, "elm_modapi_init");
             if (m->init_func)
               {
                  m->shutdown_func = eina_module_symbol_get(m->module, "elm_modapi_shutdown");
                  m->so_path = eina_stringshare_add(buf);
                  snprintf(buf, sizeof(buf), "%s/"ELEMENTARY_BASE_DIR"/modules/%s/%s", home, m->name, MODULE_ARCH);
                  m->bin_dir = eina_stringshare_add(buf);
                  snprintf(buf, sizeof(buf), "%s/"ELEMENTARY_BASE_DIR"/modules/%s", home, m->name);
                  m->data_dir = eina_stringshare_add(buf);
               }
             else
               {
                  if (m->module)
                    {
                       eina_module_unload(m->module);
                       eina_module_free(m->module);
                       m->module = NULL;
                    }
                  return EINA_FALSE;
               }
          }
        else if (m->module)
          {
            eina_module_free(m->module);
            m->module = NULL;
          }
     }

   if (!m->module)
     {
        snprintf(buf, sizeof(buf), "%s/elementary/modules/%s/%s/module" EFL_SHARED_EXTENSION, _elm_lib_dir, m->name, MODULE_ARCH);
        m->module = eina_module_new(buf);
        if (m->module && eina_module_load (m->module) == EINA_TRUE)
          {
             m->init_func = eina_module_symbol_get(m->module, "elm_modapi_init");
             if (m->init_func)
               {
                  m->shutdown_func = eina_module_symbol_get(m->module, "elm_modapi_shutdown");
                  m->so_path = eina_stringshare_add(buf);
                  snprintf(buf, sizeof(buf), "%s/elementary/modules/%s/%s", _elm_lib_dir, m->name, MODULE_ARCH);
                  m->bin_dir = eina_stringshare_add(buf);
                  snprintf(buf, sizeof(buf), "%s/elementary/modules/%s", _elm_lib_dir, m->name);
                  m->data_dir = eina_stringshare_add(buf);
               }
             else
               {
                  if (m->module)
                    {
                       eina_module_unload(m->module);
                       eina_module_free(m->module);
                       m->module = NULL;
                    }
                  return EINA_FALSE;
               }
          }
     }
   else if (m->module)
     {
       eina_module_free(m->module);
       m->module = NULL;
     }

   if (!m->module) return EINA_FALSE;
   return EINA_TRUE;
}
void deleteOwnedPtr(Eina_Module* ptr)
{
    if (ptr)
        eina_module_free(ptr); // If module wasn't unloaded, eina_module_free() calls eina_module_unload().
}
Exemple #12
0
Eina_Bool
ecore_audio_pulse_lib_load(void)
{
   if (ecore_audio_pulse_lib)
     {
        if (!ecore_audio_pulse_lib->mod)
          {
             ERR("Cannot find libpulse at runtime!");
             return EINA_FALSE;
          }
        return EINA_TRUE;
     }

   ecore_audio_pulse_lib = calloc(1, sizeof(Ecore_Audio_Lib_Pulse));
   if (!ecore_audio_pulse_lib) return EINA_FALSE;
# define LOAD(x)                                               \
   if (!ecore_audio_pulse_lib->mod) {                          \
      if ((ecore_audio_pulse_lib->mod = eina_module_new(x))) { \
         if (!eina_module_load(ecore_audio_pulse_lib->mod)) {  \
            eina_module_free(ecore_audio_pulse_lib->mod);      \
            ecore_audio_pulse_lib->mod = NULL;                 \
         }                                                     \
      }                                                        \
   }
# if defined(_WIN32) || defined(__CYGWIN__)
   LOAD("libpulse-0.dll");
   LOAD("libpulse.dll");
   LOAD("pulse.dll");
   if (!ecore_audio_pulse_lib->mod)
     ERR("Could not find libpulse-0.dll, libpulse.dll, pulse.dll");
# elif defined(__APPLE__) && defined(__MACH__)
   LOAD("libpulse.0.dylib");
   LOAD("libpulse.0.so");
   LOAD("libpulse.so.0");
   if (!ecore_audio_pulse_lib->mod)
     ERR("Could not find libpulse.0.dylib, libpulse.0.so, libpulse.so.0");
# else
   LOAD("libpulse.so.0");
   if (!ecore_audio_pulse_lib->mod)
     ERR("Could not find libpulse.so.0");
# endif
# undef LOAD
   if (!ecore_audio_pulse_lib->mod) return EINA_FALSE;

#define SYM(x) \
   if (!(ecore_audio_pulse_lib->x = eina_module_symbol_get(ecore_audio_pulse_lib->mod, #x))) { \
      ERR("Cannot find symbol '%s' in'%s", #x, eina_module_file_get(ecore_audio_pulse_lib->mod)); \
      goto err; \
   }
   SYM(pa_context_new);
   SYM(pa_context_connect);
   SYM(pa_context_set_sink_input_volume);
   SYM(pa_context_get_state);
   SYM(pa_context_set_state_callback);
   SYM(pa_operation_unref);
   SYM(pa_cvolume_set);
   SYM(pa_stream_new);
   SYM(pa_stream_unref);
   SYM(pa_stream_connect_playback);
   SYM(pa_stream_disconnect);
   SYM(pa_stream_drain);
   SYM(pa_stream_cork);
   SYM(pa_stream_write);
   SYM(pa_stream_begin_write);
   SYM(pa_stream_set_write_callback);
   SYM(pa_stream_trigger);
   SYM(pa_stream_update_sample_rate);
   SYM(pa_stream_get_index);
#undef SYM
   return EINA_TRUE;
err:
   if (ecore_audio_pulse_lib->mod)
     {
        eina_module_free(ecore_audio_pulse_lib->mod);
        ecore_audio_pulse_lib->mod = NULL;
     }
   return EINA_FALSE;
}
Exemple #13
0
Eina_Bool
ecore_audio_sndfile_lib_load(void)
{
   if (ecore_audio_sndfile_lib)
     {
        if (!ecore_audio_sndfile_lib->mod)
          {
             ERR("Cannot find libsndfile at runtime!");
             return EINA_FALSE;
          }
        return EINA_TRUE;
     }

   ecore_audio_sndfile_lib = calloc(1, sizeof(Ecore_Audio_Lib_Sndfile));
   if (!ecore_audio_sndfile_lib) return EINA_FALSE;
# define LOAD(x)                                                 \
   if (!ecore_audio_sndfile_lib->mod) {                          \
      if ((ecore_audio_sndfile_lib->mod = eina_module_new(x))) { \
         if (!eina_module_load(ecore_audio_sndfile_lib->mod)) {  \
            eina_module_free(ecore_audio_sndfile_lib->mod);      \
            ecore_audio_sndfile_lib->mod = NULL;                 \
         }                                                       \
      }                                                          \
   }
# if defined(_WIN32) || defined(__CYGWIN__)
   LOAD("libsndfile-1.dll");
   LOAD("libsndfile.dll");
   LOAD("sndfile.dll");
# elif defined(__APPLE__) && defined(__MACH__)
   LOAD("libsndfile.1.dylib");
   LOAD("libsndfile.1.so");
   LOAD("libsndfile.so.1");
# else
   LOAD("libsndfile.so.1");
# endif
# undef LOAD
   if (!ecore_audio_sndfile_lib->mod) return EINA_FALSE;

#define SYM(x) \
   if (!(ecore_audio_sndfile_lib->x = eina_module_symbol_get(ecore_audio_sndfile_lib->mod, #x))) { \
      ERR("Cannot find symbol '%s' in'%s", #x, eina_module_file_get(ecore_audio_sndfile_lib->mod)); \
      goto err; \
   }
   SYM(sf_open);
   SYM(sf_open_virtual);
   SYM(sf_close);
   SYM(sf_read_float);
   SYM(sf_write_float);
   SYM(sf_write_sync);
   SYM(sf_seek);
   SYM(sf_strerror);
#undef SYM
   return EINA_TRUE;
err:
   if (ecore_audio_sndfile_lib->mod)
     {
        eina_module_free(ecore_audio_sndfile_lib->mod);
        ecore_audio_sndfile_lib->mod = NULL;
     }
   return EINA_FALSE;
}