2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <dbus/dbus.h>
18 #include <dbus/dbus-glib-lowlevel.h>
19 #include "NotificationServer.h"
20 #include "PrivacyGuardTypes.h"
23 auto DBusConnectionDeleter = [&](DBusConnection* pPtr) { dbus_connection_close(pPtr); pPtr = NULL;};
24 const int MAX_LOCAL_BUF_SIZE = 128;
26 NotificationServer::NotificationServer(void)
27 : m_initialized(false)
28 , m_pDBusConnection(NULL)
33 NotificationServer::~NotificationServer(void)
35 if (m_pDBusConnection)
37 dbus_connection_close(m_pDBusConnection);
38 m_pDBusConnection = NULL;
43 NotificationServer::initialize(void)
46 return PRIV_FLTR_ERROR_SUCCESS;
49 dbus_error_init(&error);
51 m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
52 TryReturn(m_pDBusConnection != NULL, PRIV_FLTR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private : %s", error.message);
54 dbus_connection_setup_with_g_main(m_pDBusConnection, NULL);
55 std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);
57 snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());
59 dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);
60 TryReturn(!dbus_error_is_set(&error), PRIV_FLTR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match : %s", error.message);
63 return PRIV_FLTR_ERROR_SUCCESS;
67 NotificationServer::notifySettingChanged(const std::string pkgId, const std::string privacyId)
70 return PRIV_FLTR_ERROR_INVALID_STATE;
72 char* pPkgId = const_cast <char*> (pkgId.c_str());
73 char* pPrivacyId = const_cast <char*> (privacyId.c_str());
75 DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str());
76 TryReturn(pMessage != NULL, PRIV_FLTR_ERROR_IPC_ERROR, , "dbus_message_new_signal");
79 r = dbus_message_append_args(pMessage,
80 DBUS_TYPE_STRING, &pPkgId,
81 DBUS_TYPE_STRING, &pPrivacyId,
83 TryReturn(r, PRIV_FLTR_ERROR_IPC_ERROR, , "dbus_message_append_args");
85 r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
86 TryReturn(r, PRIV_FLTR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
88 dbus_connection_flush(m_pDBusConnection);
89 dbus_message_unref(pMessage);
91 return PRIV_FLTR_ERROR_SUCCESS;
95 NotificationServer::notifyPkgRemoved(const std::string pkgId)
98 return PRIV_FLTR_ERROR_INVALID_STATE;
100 char* pPkgId = const_cast <char*> (pkgId.c_str());
102 DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str());
103 TryReturn(pMessage != NULL, PRIV_FLTR_ERROR_IPC_ERROR, , "dbus_message_new_signal");
106 r = dbus_message_append_args(pMessage,
107 DBUS_TYPE_STRING, &pPkgId,
109 TryReturn(r, PRIV_FLTR_ERROR_IPC_ERROR, , "dbus_message_append_args");
111 r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
112 TryReturn(r, PRIV_FLTR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
114 dbus_connection_flush(m_pDBusConnection);
115 dbus_message_unref(pMessage);
117 return PRIV_FLTR_ERROR_SUCCESS;