tizen 2.4 release
[framework/uifw/cbhm.git] / 2.3-wearable / src / cbhm.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #ifndef _CBHM_H_
19 #define _CBHM_H_
20
21 #include <Elementary.h>
22 #include <Ecore_X.h>
23
24 #if !defined(PACKAGE)
25 #  define PACKAGE "CBHM"
26 #endif
27
28 #if !defined(APPNAME)
29 #  define APPNAME "Clipboard History Manager"
30 #endif
31
32 #define CBHM_MAGIC 0xad960009
33
34 typedef struct _TargetHandler TargetHandler;
35 typedef struct _AppData AppData;
36 typedef struct _ClipdrawerData ClipdrawerData;
37 typedef struct _CNP_ITEM CNP_ITEM;
38 typedef struct _XHandlerData XHandlerData;
39 typedef struct _StorageData StorageData;
40 typedef char *(*text_converter_func)(AppData *ad, int type_index, const char *str);
41
42 #define ITEM_CNT_MAX 20
43 #define COPIED_DATA_STORAGE_DIR DATADIR"/.cbhm_files"
44
45 #include "clipdrawer.h"
46 #include "item_manager.h"
47 #include "xhandler.h"
48 #include "xconverter.h"
49 #include "storage.h"
50
51 struct _TargetHandler {
52         Ecore_X_Atom *atom;
53         char **name;
54         int atom_cnt;
55         text_converter_func convert_to_entry;
56         text_converter_func convert_to_target[ATOM_INDEX_MAX];
57 };
58
59 struct _AppData {
60         int magic;
61         Ecore_X_Display *x_disp;
62         Ecore_X_Window x_root_win;
63         Ecore_X_Window x_event_win;
64         Ecore_X_Window x_active_win;
65         Eina_List *item_list;
66
67         Eina_Bool (*draw_item_add)(AppData *ad, CNP_ITEM *item);
68         Eina_Bool (*draw_item_del)(AppData *ad, CNP_ITEM *item);
69         Eina_Bool (*storage_item_add)(AppData *ad, CNP_ITEM *item);
70         Eina_Bool (*storage_item_del)(AppData *ad, CNP_ITEM *item);
71         Eina_Bool (*storage_item_update)(AppData *ad, CNP_ITEM *item);
72         CNP_ITEM *(*storage_item_load)(StorageData *sd, int index);
73
74         ClipdrawerData *clipdrawer;
75         XHandlerData *xhandler;
76         StorageData *storage;
77
78         CNP_ITEM *clip_selected_item;
79         TargetHandler targetAtoms[ATOM_INDEX_MAX];
80 };
81
82 void *d_malloc(const char *func, int line, size_t size);
83 void *d_calloc(const char *func, int line, size_t n, size_t size);
84 void d_free(const char *func, int line, void *m);
85
86 extern int _log_domain;
87 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_log_domain, __VA_ARGS__)
88 #define ERR(...)      EINA_LOG_DOM_ERR(_log_domain, __VA_ARGS__)
89 #define WRN(...)      EINA_LOG_DOM_WARN(_log_domain, __VA_ARGS__)
90 #define INF(...)      EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
91 #define DBG(...)      EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
92 #define CALLED() DBG("called %s, %s", __FILE__, __func__);
93 #define MALLOC(size) d_malloc(__func__, __LINE__, size)
94 #define CALLOC(n, size) d_calloc(__func__, __LINE__, n, size)
95 #define FREE(p) d_free(__func__, __LINE__, p)
96
97 // Define memory-safe string functions
98 #define SAFE_STRCMP(s1, s2) ((s1 && s2) ? strcmp(s1, s2) : (s1 ? 1 : -1))
99 #define SAFE_STRNCMP(s1, s2, n) ((s1 && s2) ? strncmp(s1, s2, n) : (s1 ? 1 : -1))
100 #define SAFE_STRDUP(s) (s ? strdup(s) : NULL)
101 #define SAFE_STRNDUP(s, n) (s ? strndup(s, n) : NULL)
102 #define SAFE_STRCPY(dest, src) (src ? strcpy(dest, src) : NULL)
103 #define SAFE_STRNCPY(dest, src, n) (src ? strncpy(dest, src, n) : NULL)
104 #define SAFE_STRCAT(dest, src) ((dest && src) ? strcat(dest, src) : NULL)
105 #define SAFE_STRNCAT(dest, src, n) ((dest && src) ? strncat(dest, src, n) : NULL)
106 #define SAFE_STRCHR(s, c) (s ? strchr(s, c) : NULL)
107 #define SAFE_STRSTR(haystack, needle) (haystack ? strstr(haystack, needle) : NULL)
108 #define SAFE_STRLEN(s) (s ? strlen(s) : 0)
109
110 #endif // _CBHM_H_