add scene probe
[platform/core/system/swap-probe.git] / include / dacollection.h
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  *
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  *
29  */
30
31 #ifndef __COLLECTIONS_H__
32 #define __COLLECTIONS_H__
33
34 #include <pthread.h>                    // for pthread_mutex_t
35
36 #include "khash.h"
37
38 #ifdef __cplusplus
39 extern "C"{
40 #endif
41
42 #define SYMBOLHASH                      _hashinfo.symHash
43 #define SYMBOLHASH_LOCK         pthread_mutex_lock(&(_hashinfo.symHashMutex))
44 #define SYMBOLHASH_UNLOCK       pthread_mutex_unlock(&(_hashinfo.symHashMutex))
45
46 #define MEMORYHASH                      _hashinfo.memHash
47 #define MEMORYHASH_LOCK         pthread_mutex_lock(&(_hashinfo.memHashMutex))
48 #define MEMORYHASH_UNLOCK       pthread_mutex_unlock(&(_hashinfo.memHashMutex))
49
50 #define OBJECTHASH                      _hashinfo.objHash
51 #define OBJECTHASH_LOCK         pthread_mutex_lock(&(_hashinfo.objHashMutex))
52 #define OBJECTHASH_UNLOCK       pthread_mutex_unlock(&(_hashinfo.objHashMutex))
53
54 #define DETECTORHASH            _hashinfo.dttHash
55 #define DETECTORHASH_LOCK       pthread_mutex_lock(&(_hashinfo.dttHashMutex))
56 #define DETECTORHASH_UNLOCK     pthread_mutex_unlock(&(_hashinfo.dttHashMutex))
57
58 typedef struct
59 {
60         char* type;
61         char* name;
62 } _objectinfo;
63
64 // khash table function definition
65 KHASH_MAP_INIT_INT(symbol, char*)
66
67 KHASH_MAP_INIT_INT(allocmap, size_t)
68
69 KHASH_MAP_INIT_INT(object, _objectinfo*)
70
71 KHASH_MAP_INIT_INT(detector, void*)
72
73 typedef struct
74 {
75         khash_t(symbol)*        symHash;
76         pthread_mutex_t         symHashMutex;
77         khash_t(allocmap)*      memHash;
78         pthread_mutex_t         memHashMutex;
79         khash_t(object)*        objHash;
80         pthread_mutex_t         objHashMutex;
81         khash_t(detector)*      dttHash;
82         pthread_mutex_t         dttHashMutex;
83 } __hashInfo;
84
85 extern __hashInfo _hashinfo;
86
87 // APIs for symdata linked list
88 int add_to_glist(char* key, void* data);
89 int remove_from_glist(char* key);
90 int remove_all_glist();
91 void* find_glist(char* key);
92
93 // APIs for hash table
94 int initialize_hash_table();
95 int finalize_hash_table();
96
97 int find_symbol_hash(void* ptr, char** psymbol);
98 int add_symbol_hash(void* ptr, const char* str, int strlen);
99 int add_memory_hash(void* ptr, size_t size);
100 int del_memory_hash(void* ptr);
101
102 int find_object_hash(void* ptr, char** type,  char** classname);
103 int add_object_hash_class(void* ptr, const char* classname);
104 int add_object_hash_type(void* ptr, const char* type);
105 int del_object_hash(void* ptr);
106
107 int add_detector_hash(void* ptr, void* listener);
108 int del_detector_hash(void* ptr);
109
110 #ifdef __cplusplus
111 }
112 #endif
113
114 #endif /* __COLLECTIONS_H_ */