Implement ServiceCallbacks 08/122208/16
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 30 Mar 2017 13:05:10 +0000 (15:05 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 3 Apr 2017 18:53:11 +0000 (20:53 +0200)
Add implemenation of ServiceCallbacks for handling
client requests.

Change-Id: I7fd1bde8bfc9f2ba3d630375aadfdcf16028effc

src/agent/CMakeLists.txt
src/agent/notification-daemon/CMakeLists.txt
src/agent/notification-daemon/ServerCallbacks.cpp [new file with mode: 0644]
src/agent/notification-daemon/ServerCallbacks.h [new file with mode: 0644]

index 17f0dd7..c3120ac 100644 (file)
@@ -39,6 +39,7 @@ SET(ASKUSER_SOURCES
 
 INCLUDE_DIRECTORIES(
     ${ASKUSER_PATH}/common
+    ${ASKUSER_PATH}/common/protocol
     ${AGENT_DEP_INCLUDE_DIRS}
     ${ASKUSER_AGENT_PATH}
     )
index ef1facc..83b671f 100644 (file)
@@ -24,12 +24,14 @@ INCLUDE_DIRECTORIES(SYSTEM
 INCLUDE_DIRECTORIES(
     ${ASKUSER_PATH}
     ${ASKUSER_PATH}/common
+    ${ASKUSER_PATH}/common/protocol
 )
 
 SET(ASKUSER_NOTIFICATION_SOURCES
     ${NOTIF_PATH}/main.cpp
     ${NOTIF_PATH}/GuiRunner.cpp
     ${NOTIF_PATH}/AskUserTalker.cpp
+    ${NOTIF_PATH}/ServerCallbacks.cpp
     ${NOTIF_PATH}/ui/Po.cpp
     ${ASKUSER_PATH}/common/log/alog.cpp
     ${ASKUSER_PATH}/common/socket/Socket.cpp
@@ -51,6 +53,7 @@ SET_TARGET_PROPERTIES(${TARGET_ASKUSER_NOTIFICATION} PROPERTIES
 TARGET_LINK_LIBRARIES(${TARGET_ASKUSER_NOTIFICATION}
     ${ASKUSER_NOTIFICATION_DEP_LIBRARIES}
     ${TARGET_ASKUSER_COMMON}
+    ${TARGET_ASKUSER_NOTIFICATION_LIB}
     -pie
 )
 
diff --git a/src/agent/notification-daemon/ServerCallbacks.cpp b/src/agent/notification-daemon/ServerCallbacks.cpp
new file mode 100644 (file)
index 0000000..97ac799
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co.
+ *
+ *  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
+ */
+/**
+ * @file        src/agent/notification-daemon/ServerCallbacks.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief       Implementation ServerCallbacks classes
+ */
+#include <unistd.h>
+
+#include "ServerCallbacks.h"
+#include "event/Event.h"
+
+namespace {
+Ecore_Fd_Handler_Flags maskToFlags(int mask) {
+    int flags = ECORE_FD_ERROR;
+    if (mask & AskUser::Protocol::READ)
+        flags |= static_cast<int>(ECORE_FD_READ);
+    if (mask & AskUser::Protocol::WRITE)
+        flags |= static_cast<int>(ECORE_FD_WRITE);
+    return static_cast<Ecore_Fd_Handler_Flags>(flags);
+}
+}
+
+namespace AskUser {
+namespace Protocol {
+
+void ServerCallbacks::updateFd(int fd, int mask) {
+    if (mask == 0)
+        m_service->removeChannelFd(fd);
+    else
+        m_service->addChannelFd(fd, maskToFlags(mask));
+}
+
+void ServerCallbacks::popup_launch(int requestId, const std::string &pkgName,
+                                   const std::string &appName, uid_t,
+                                   const AskUser::Protocol::PrivilegeVector &privileges)
+{
+    m_service->addEvent(new AskUser::Notification::EventPopupLaunch(m_popupper, requestId, appName, pkgName, privileges));
+}
+void ServerCallbacks::toast_deny(const std::string &pkgName, const std::string &appName,
+                                  uid_t, const AskUser::Protocol::Privilege &privilege)
+{
+    m_service->addEvent(new AskUser::Notification::EventToastDeny(m_popupper, 0, appName, pkgName, privilege));
+}
+void ServerCallbacks::toast_fail_launch(const std::string &pkgName, const std::string &appName,
+                                         uid_t)
+{
+    m_service->addEvent(new AskUser::Notification::EventToastFail(m_popupper, 0, appName, pkgName));
+}
+
+} /* namespace Notification */
+} /* namespace Askuser */
diff --git a/src/agent/notification-daemon/ServerCallbacks.h b/src/agent/notification-daemon/ServerCallbacks.h
new file mode 100644 (file)
index 0000000..f8ca6fb
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co.
+ *
+ *  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
+ */
+/**
+ * @file        src/agent/notification-daemon/ServerCallbacks.h
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief       Declaration of ServerCallbacks classes
+ */
+#pragma once
+
+#include <memory>
+
+#include <askuser-notification/ask-user-service.h>
+
+#include "Logic.h"
+#include "ui/Popupper.h"
+
+namespace AskUser {
+namespace Protocol {
+
+class ServerCallbacks : public IServerCallbacks {
+public:
+    ServerCallbacks(AskUser::Notification::Logic *logic, AskUser::Notification::Popupper *popupper)
+        : m_service(logic), m_popupper(popupper)
+    {}
+    virtual void updateFd(int fd, int mask);
+    virtual void popup_launch(int requestId, const std::string &pkgName,
+                              const std::string &appName, uid_t uid,
+                              const AskUser::Protocol::PrivilegeVector &privileges);
+    virtual void toast_deny(const std::string &pkgName, const std::string &appName,
+                            uid_t uid, const AskUser::Protocol::Privilege &privilege);
+    virtual void toast_fail_launch(const std::string &pkgName, const std::string &appName,
+                                   uid_t uid);
+    virtual ~ServerCallbacks() {}
+private:
+    AskUser::Notification::Logic *m_service;
+    AskUser::Notification::Popupper *m_popupper;
+};
+
+} /* namespace Notification */
+} /* namespace Askuser */
+