modify logs
[platform/core/security/privacy-manager.git] / client / inc / PrivacyChecker.h
1 /*
2  * Copyright (c) 2012 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 #ifndef _PRIVACY_CHECKER_H_
18 #define _PRIVACY_CHECKER_H_
19
20 #include <string>
21 #include <mutex>
22 #include <list>
23 #include <vector>
24 #include <memory>
25 #include <map>
26 #include <PrivacyManagerTypes.h>
27 #include <dbus/dbus.h>
28 #include <glib.h>
29
30 struct sqlite3;
31
32 class EXTERN_API PrivacyChecker
33 {
34 private:
35         static std::map < std::string, bool > m_privacyCache;
36         static std::map < std::string, std::map < std::string, bool > > m_privacyInfoCache;
37         static std::string m_pkgId;
38         static bool m_isInitialized;
39         static std::mutex m_cacheMutex;
40         static DBusConnection* m_pDBusConnection;
41         static GMainLoop* m_pLoop;
42         static GMainContext* m_pHandlerGMainContext;
43         static pthread_t m_signalThread;
44
45 private:
46         static int initializeDbus(void);
47         static int finalizeDbus(void);
48         static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap);
49         static int updateCache(const std::string pkgId, std::map < std::string, bool >& pkgCacheMap);
50         static void printCache(void);
51         static void* runSignalListenerThread(void* pData);
52         static int getCurrentPkgId(std::string& pkgId);
53         static int check(const std::string privacyId, std::map < std::string, bool >& privacyMap);
54
55 public:
56         // for Checking in App Process
57         static int initialize(const std::string pkgId);
58         static int check(const std::string pkgId, const std::string privacyId);
59         static int checkWithPrivilege(const std::string pkgId, const std::string privilegeId);
60         static int checkWithDeviceCap(const std::string pkgId, const std::string deviceCap);
61         
62         // for Checking in Server Process
63         static int initialize(void);
64         static int check(const std::string privacyId);
65         static int checkWithPrivilege(const std::string privilegeId);
66         static int checkWithDeviceCap(const std::string deviceCap);
67         
68         // common
69         static int finalize(void);
70         static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data);
71 };
72
73 #endif // _PRIVACY_CHECKER_H_