weekeyboard_SOURCES= \
wkb-main.c \
+ wkb-log.c \
+ wkb-log.h \
input-method-protocol.c \
input-method-client-protocol.h \
text-protocol.c \
weekeyboard-config-eet-test
weekeyboard_config_eet_test_SOURCES = \
+ wkb-log.c \
+ wkb-log.h \
wkb-ibus-config-key.c \
wkb-ibus-config-key.h \
wkb-ibus-config-eet.c \
weekeyboard_ibus_test_SOURCES = \
wkb-ibus.h \
wkb-ibus.c \
+ wkb-log.c \
+ wkb-log.h \
wkb-ibus-defs.h \
wkb-ibus-panel.c \
wkb-ibus-config.c \
*/
#include <stdio.h>
-#include <Eina.h>
#include <Eet.h>
#include "wkb-ibus-config-eet.h"
+#include "wkb-log.h"
int
main (int argc, char *argv[])
{
+ int ret = 1;
struct wkb_ibus_config_eet *cfg;
- if (!eina_init())
- {
- printf("Error initializing eina");
- return 1;
- }
+ if (!wkb_log_init("eet-test"))
+ return 1;
- if (!eet_init())
+ if (!wkb_ibus_config_eet_init())
{
- printf("Error initializing eet");
+ ERR("Error initializing eet");
goto eet_err;
}
cfg = wkb_ibus_config_eet_new("ibus-cfg.eet", NULL);
wkb_ibus_config_eet_free(cfg);
-
-end:
- eet_shutdown();
+ ret = 0;
+ wkb_ibus_config_eet_shutdown();
eet_err:
- eina_shutdown();
+ wkb_log_shutdown();
- return 0;
+ return ret;
}
#include "wkb-ibus-config-eet.h"
#include "wkb-ibus-config-key.h"
+#include "wkb-log.h"
/*
* Base struct for all config types
if (base->id && !strncasecmp(section, base->id, strlen(section)))
{
- printf("Requested section: '%s' match: '%s' \n", section, base->id);
+ DBG("Requested section: '%s' match: '%s'", section, base->id);
return base;
}
if (!(sec = _config_section_find(base, section)))
{
- printf("Config section with id '%s' not found\n", section);
+ DBG("Config section with id '%s' not found", section);
goto end;
}
key_id = wkb_config_key_id(key);
if (!strcasecmp(name, key_id))
{
- printf("Requested key: '%s' match: '%s'\n", name, key_id);
+ DBG("Requested key: '%s' match: '%s'", name, key_id);
ret = key;
break;
}
if (!(key = _config_section_find_key(config_eet->ibus_config, section, name)))
{
- printf("Config key with id '%s' not found\n", name);
+ ERR("Config key with id '%s' not found", name);
goto end;
}
if (!ef || !eet_data_write(ef, config_eet->ibus_edd, "ibus", config_eet->ibus_config, EINA_TRUE))
{
// FIXME
- printf("Error writing Eet file '%s'\n", config_eet->path);
+ ERR("Error writing Eet file '%s'", config_eet->path);
ret = EINA_FALSE;
}
eet_close(ef);
if (!(key = _config_section_find_key(config_eet->ibus_config, section, name)))
{
- printf("Config key with id '%s' not found\n", name);
+ ERR("Config key with id '%s' not found", name);
goto end;
}
if (!(sec = _config_section_find(config_eet->ibus_config, section)))
{
- printf("Config section with id '%s' not found\n", section);
+ ERR("Config section with id '%s' not found", section);
goto end;
}
if (!(ef = eet_open(path, mode)))
{
- printf("Error opening eet file '%s' for %s\n", path, mode == EET_FILE_MODE_READ ? "read" : "write");
+ ERR("Error opening eet file '%s' for %s", path, mode == EET_FILE_MODE_READ ? "read" : "write");
wkb_ibus_config_eet_free(eet);
return NULL;
}
wkb_ibus_config_eet_set_defaults(eet);
if (!eet_data_write(ef, eet->ibus_edd, "ibus", eet->ibus_config, EINA_TRUE))
{
- printf("Error creating eet file '%s'\n", path);
+ ERR("Error creating eet file '%s'", path);
wkb_ibus_config_eet_free(eet);
eet = NULL;
}
free(config_eet);
}
+
+static int _init_count = 0;
+
+int
+wkb_ibus_config_eet_init(void)
+{
+ if (_init_count)
+ goto end;
+
+ if (!eet_init())
+ {
+ ERR("Error initializing Eet");
+ return 0;
+ }
+
+end:
+ return ++_init_count;
+}
+
+void
+wkb_ibus_config_eet_shutdown()
+{
+ if (_init_count <= 0 || --_init_count > 0)
+ return;
+
+ eet_shutdown();
+}
struct wkb_ibus_config_eet *wkb_ibus_config_eet_new(const char *path, Eldbus_Service_Interface *iface);
void wkb_ibus_config_eet_free(struct wkb_ibus_config_eet *config_eet);
+int wkb_ibus_config_eet_init(void);
+void wkb_ibus_config_eet_shutdown(void);
+
#endif /* _WKB_IBUS_CONFIG_EET_H_ */
#include <unistd.h>
#include <string.h>
-#include <Eina.h>
-
#include "wkb-ibus-config-key.h"
+#include "wkb-log.h"
typedef void (*key_free_cb) (void *);
typedef Eina_Bool (*key_set_cb) (struct wkb_config_key *, Eldbus_Message_Iter *);
_type *__field = (_type *) _key->field; \
if (!eldbus_message_iter_arguments_get(iter, _key->signature, &__value)) \
{ \
- printf("Error decoding " #_type " value using '%s'\n", _key->signature); \
+ ERR("Error decoding " #_type " value using '%s'", _key->signature); \
return EINA_FALSE; \
} \
*__field = __value; \
if (iter && !eldbus_message_iter_arguments_get(iter, "s", &str))
{
- printf("Error decoding string value using 's'\n");
+ ERR("Error decoding string value using 's'");
return EINA_FALSE;
}
if (!(ret = key->get(key, value)))
{
- printf("Unexpected error retrieving value for key: '%s'\n", key->id);
+ ERR("Unexpected error retrieving value for key: '%s'", key->id);
}
eldbus_message_iter_container_close(reply, value);
#include <Eina.h>
#include <Eldbus.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct wkb_config_key;
struct wkb_config_key *wkb_config_key_int(const char *id, void *field);
Eina_Bool wkb_config_key_set(struct wkb_config_key * key, Eldbus_Message_Iter *iter);
Eina_Bool wkb_config_key_get(struct wkb_config_key *key, Eldbus_Message_Iter *reply);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _WKB_IBUS_CONFIG_KEY_H_ */
#include "wkb-ibus.h"
#include "wkb-ibus-defs.h"
#include "wkb-ibus-config-eet.h"
+#include "wkb-log.h"
static struct wkb_ibus_config_eet *_conf_eet = NULL;
#include "wkb-ibus.h"
#include "wkb-ibus-defs.h"
+#include "wkb-log.h"
#define _panel_check_message_errors(_msg) \
do \
*/
#include "wkb-ibus.h"
+#include "wkb-log.h"
#define _GNU_SOURCE
#include <signal.h>
static void
_finish(int foo)
{
- printf("FINISH\n");
+ ERR("FINISH\n");
wkb_ibus_shutdown();
}
int
main (int argc, char *argv[])
{
- int ret = 0;
- if (!eet_init())
- {
- printf("Error initializing eet");
- return 1;
- }
+ int ret = 1;
+
+ if (!wkb_log_init("ibus-test"))
+ return 1;
if (!ecore_init())
{
- printf("Error initializing ecore");
- ret = 1;
+ ERR("Error initializing ecore");
goto ecore_err;
}
- if (!eldbus_init())
- {
- printf("Error initializing eldbus");
- ret = 1;
- goto eldbus_err;
- }
-
if (!efreet_init())
{
- printf("Error initializing efreet");
- ret = 1;
+ ERR("Error initializing efreet");
goto efreet_err;
}
if (!wkb_ibus_init())
{
- printf("Error initializing ibus");
- ret = 1;
+ ERR("Error initializing ibus");
goto end;
}
signal(SIGINT, _finish);
ecore_main_loop_begin();
+ ret = 0;
end:
efreet_shutdown();
efreet_err:
- eldbus_shutdown();
-
-eldbus_err:
ecore_shutdown();
ecore_err:
eet_shutdown();
+eet_err:
+ wkb_log_shutdown();
+
return ret;
}
#include "wkb-ibus.h"
#include "wkb-ibus-defs.h"
-
-int _wkb_ibus_log_dom = -1;
+#include "wkb-log.h"
#define _check_message_errors(_msg) \
do \
return EINA_TRUE;
}
-
int
wkb_ibus_init(void)
{
- if (ctx && ctx->refcount > 0)
+ if (ctx && ctx->refcount)
goto end;
- if (!eina_init())
+ if (!eldbus_init())
{
- fprintf(stderr, "Error initializing Eina\n");
+ ERR("Error initializing Eldbus");
return 0;
}
- _wkb_ibus_log_dom = eina_log_domain_register("wkb-ibus", EINA_COLOR_LIGHTCYAN);
- if (_wkb_ibus_log_dom < 0)
- {
- EINA_LOG_ERR("Unable to register 'wkb-ibus' log domain");
- eina_shutdown();
- return 0;
- }
+ if (!wkb_ibus_config_eet_init())
+ {
+ ERR("Error initializing wkb_config_eetn");
+ eldbus_shutdown();
+ return -0;
+ }
if (!ctx && !(ctx = calloc(1, sizeof(*ctx))))
{
- ERR("Error calloc\n");
- eina_shutdown();
+ ERR("Error calloc");
+ eldbus_shutdown();
return 0;
}
{
if (!ctx)
{
- fprintf(stderr, "Not initialized\n");
+ ERR("Not initialized");
return;
}
extern "C" {
#endif
-extern int _wkb_ibus_log_dom;
-#define DBG(...) EINA_LOG_DOM_DBG(_wkb_ibus_log_dom, __VA_ARGS__)
-#define INF(...) EINA_LOG_DOM_INFO(_wkb_ibus_log_dom, __VA_ARGS__)
-#define WRN(...) EINA_LOG_DOM_WARN(_wkb_ibus_log_dom, __VA_ARGS__)
-#define ERR(...) EINA_LOG_DOM_ERR(_wkb_ibus_log_dom, __VA_ARGS__)
-#define CRITICAL(...) EINA_LOG_DOM_CRIT(_wkb_ibus_log_dom, __VA_ARGS__)
-
int wkb_ibus_init(void);
void wkb_ibus_shutdown(void);
--- /dev/null
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wkb-log.h"
+
+int _wkb_log_domain = -1;
+static int _init_count = 0;
+
+int
+wkb_log_init(const char *domain)
+{
+ if (_init_count)
+ goto end;
+
+ if (!eina_init())
+ {
+ fprintf(stderr, "%s:%d - %s() Error initializing Eina\n", __FILE__, __LINE__, __FUNCTION__);
+ return 0;
+ }
+
+ _wkb_log_domain = eina_log_domain_register(domain, EINA_COLOR_LIGHTCYAN);
+
+ if (_wkb_log_domain < 0)
+ {
+ EINA_LOG_ERR("Unable to register '%s' log domain", domain);
+ eina_shutdown();
+ return 0;
+ }
+
+end:
+ return ++_init_count;
+}
+
+void
+wkb_log_shutdown(void)
+{
+ if (_init_count <= 0 || --_init_count > 0)
+ return;
+
+ eina_log_domain_unregister(_wkb_log_domain);
+ eina_shutdown();
+}
--- /dev/null
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _WKB_LOG_H_
+#define _WKB_LOG_H_
+
+#include <Eina.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int _wkb_log_domain;
+#define DBG(...) EINA_LOG_DOM_DBG(_wkb_log_domain, __VA_ARGS__)
+#define INF(...) EINA_LOG_DOM_INFO(_wkb_log_domain, __VA_ARGS__)
+#define WRN(...) EINA_LOG_DOM_WARN(_wkb_log_domain, __VA_ARGS__)
+#define ERR(...) EINA_LOG_DOM_ERR(_wkb_log_domain, __VA_ARGS__)
+#define CRITICAL(...) EINA_LOG_DOM_CRIT(_wkb_log_domain, __VA_ARGS__)
+
+int wkb_log_init(const char *domain);
+void wkb_log_shutdown(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _WKB_LOG_H_ */
#include <stdlib.h>
#include <string.h>
+#include "wkb-log.h"
#include "input-method-client-protocol.h"
#include "text-client-protocol.h"
if (_wkb_ignore_key(wkb, key))
{
- printf("Ignoring key '%s'\n", key);
+ DBG("Ignoring key: '%s'", key);
goto end;
}
else if (strcmp(key, "backspace") == 0)
key = " ";
}
- printf("KEY = '%s'\n", key);
+ DBG("Key pressed: '%s'", key);
_wkb_update_preedit_str(wkb, key);
{
struct weekeyboard *wkb = data;
- printf("%s()\n", __FUNCTION__);
+ DBG("");
free(wkb->surrounding_text);
wkb->surrounding_text = strdup(text);
wkb->surrounding_cursor = cursor;
{
struct weekeyboard *wkb = data;
- printf("%s()\n", __FUNCTION__);
+ DBG("");
if (strlen(wkb->preedit_str))
{
{
struct weekeyboard *wkb = data;
- printf("%s(): im_context = %p hint = %d purpose = %d\n", __FUNCTION__, im_ctx, hint, purpose);
+ DBG("im_context = %p hint = %d purpose = %d", im_ctx, hint, purpose);
if (!wkb->context_changed)
return;
{
struct weekeyboard *wkb = data;
- printf("%s()\n", __FUNCTION__);
+ DBG("");
if (button != BTN_LEFT)
return;
{
struct weekeyboard *wkb = data;
- printf("%s()\n", __FUNCTION__);
+ DBG("");
if (wkb->surrounding_text)
- fprintf(stderr, "Surrounding text updated: %s\n", wkb->surrounding_text);
+ INF("Surrounding text updated: %s", wkb->surrounding_text);
wkb->serial = serial;
/* FIXME */
if (language)
{
wkb->language = strdup(language);
- printf("Language changed, new: '%s\n", language);
+ INF("Language changed, new: '%s'", language);
}
}
w = 600;
sprintf(path, PKGDATADIR"/default_%d.edj", w);
- printf("Loading edje file: '%s'\n", path);
+ DBG("Loading edje file: '%s'", path);
if (!edje_object_file_set(wkb->edje_obj, path, "main"))
{
int err = edje_object_load_error_get(wkb->edje_obj);
- fprintf(stderr, "error loading the edje file:%s\n", edje_load_error_str(err));
+ ERR("error loading the edje file: '%s'", edje_load_error_str(err));
return EINA_FALSE;
}
ignore_keys = edje_file_data_get(path, "ignore-keys");
if (!ignore_keys)
{
- printf("Special keys file not found in '%s'\n", path);
+ ERR("Special keys file not found in: '%s'", path);
goto end;
}
- printf("Got ignore keys = %s\n", ignore_keys);
+ DBG("Got ignore keys: '%s'", ignore_keys);
wkb->ignore_keys = eina_str_split(ignore_keys, "\n", 0);
free(ignore_keys);
env = "wayland_egl";
else
{
- printf("ERROR: Ecore_Evas does must be compiled with support for Wayland engines\n");
+ ERR("ERROR: Ecore_Evas does must be compiled with support for Wayland engines");
goto err;
}
}
else if (strcmp(env, "wayland_shm") != 0 && strcmp(env, "wayland_egl") != 0)
{
- printf("ERROR: ECORE_EVAS_ENGINE must be set to either 'wayland_shm' or 'wayland_egl'\n");
+ ERR("ERROR: ECORE_EVAS_ENGINE must be set to either 'wayland_shm' or 'wayland_egl'");
goto err;
}
struct weekeyboard wkb = {0};
int ret = EXIT_FAILURE;
- if (!ecore_init())
+ if (!wkb_log_init("weekeyboard"))
return ret;
if (!ecore_evas_init())
- goto ecore_err;
+ goto log_err;
if (!edje_init())
goto ee_err;
if (!_wkb_check_evas_engine(&wkb))
goto edj_err;
- printf("SELECTED ENGINE = %s\n", wkb.ee_engine);
+ DBG("Selected engine: '%s'", wkb.ee_engine);
wkb.ee = ecore_evas_new(wkb.ee_engine, 0, 0, 1, 1, "frame=0");
if (!wkb.ee)
{
- printf("ERROR: Unable to create Ecore_Evas object\n");
+ ERR("ERROR: Unable to create Ecore_Evas object");
goto edj_err;
}
ee_err:
ecore_evas_shutdown();
-ecore_err:
- ecore_shutdown();
+log_err:
+ wkb_log_shutdown();
return ret;
}