Add ipc library to build and packaging process 81/122481/3
authorDariusz Michaluk <d.michaluk@samsung.com>
Fri, 31 Mar 2017 08:36:05 +0000 (10:36 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 31 Mar 2017 16:43:44 +0000 (18:43 +0200)
Change-Id: Ie698e594751c65a915d6f964a847b1c8485815e3

16 files changed:
CMakeLists.txt
packaging/askuser.spec
packaging/libaskuser-notification.manifest [new file with mode: 0644]
src/common/protocol/CMakeLists.txt
src/common/protocol/ask-user-client.cpp
src/common/protocol/ask-user/ask-user-client.h [deleted file]
src/common/protocol/ask-user/ask-user-service.h [deleted file]
src/common/protocol/ask-user/ask-user-types.h [deleted file]
src/common/protocol/askuser-notification.pc.in [new file with mode: 0644]
src/common/protocol/askuser-notification/ask-user-client.h [new file with mode: 0644]
src/common/protocol/askuser-notification/ask-user-service.h [new file with mode: 0644]
src/common/protocol/askuser-notification/ask-user-types.h [new file with mode: 0644]
src/common/protocol/channel.cpp
src/common/protocol/channel.h
src/common/protocol/main.cpp
src/common/protocol/sock.cpp

index 213d9c7fd66bfd7b32d968b050747a87162433d4..538b952e2d20c12f71dd4d34d564cad8e5c1ce9c 100644 (file)
@@ -90,14 +90,17 @@ SET(ASKUSER_PATH ${PROJECT_SOURCE_DIR}/src)
 IF (BUILD_ASKUSER)
     SET(TARGET_ASKUSER "askuser")
     SET(TARGET_ASKUSER_COMMON "askuser-common")
+    SET(TARGET_ASKUSER_NOTIFICATION_LIB "askuser-notification")
     SET(TARGET_PLUGIN_SERVICE "askuser-plugin-service")
     SET(TARGET_PLUGIN_CLIENT "askuser-plugin-client")
     SET(TARGET_PRIVACYDENIED_PLUGIN_CLIENT "privacy-denied-plugin-client")
     SET(TARGET_PRIVACYDENIED_PLUGIN_SERVICE "privacy-denied-plugin-service")
     SET(TARGET_TEST "askuser-test")
     SET(TARGET_TESTS "askuser-tests")
+    SET(TARGET_ASKUSER_NOTIFICATION_TEST "askuser-notification-test")
     ADD_SUBDIRECTORY(src/agent)
     ADD_SUBDIRECTORY(src/common)
+    ADD_SUBDIRECTORY(src/common/protocol)
     ADD_SUBDIRECTORY(src/plugin)
     ADD_SUBDIRECTORY(test)
 ENDIF (BUILD_ASKUSER)
index 62e2ae5c3baab35936497caf9aba35853bde4bae..e1530d4011acdf9b65e9975f91b9eaced88dc525 100644 (file)
@@ -14,6 +14,7 @@ Source1002:    libaskuser-common.manifest
 Source1003:    askuser-plugins.manifest
 Source1004:    askuser-test.manifest
 Source1005:    privacy-denied-plugins.manifest
+Source1006:    libaskuser-notification.manifest
 BuildRequires: cmake
 BuildRequires: pkgconfig(cynara-agent)
 %if %{with_systemd_daemon}
@@ -38,6 +39,18 @@ Summary:    Askuser common library
 %description -n libaskuser-common
 Askuser common library with common functionalities
 
+%package -n libaskuser-notification
+Summary:    Askuser notification protocol library
+
+%description -n libaskuser-notification
+Askuser notification protocol library
+
+%package -n libaskuser-notification-devel
+Summary:    Askuser notification protocol library development files
+
+%description -n libaskuser-notification-devel
+Askuser notification protocol library development files
+
 %package -n askuser-plugins
 BuildRequires: pkgconfig(cynara-plugin)
 Requires:   cynara
@@ -74,6 +87,7 @@ cp -a %{SOURCE1002} .
 cp -a %{SOURCE1003} .
 cp -a %{SOURCE1004} .
 cp -a %{SOURCE1005} .
+cp -a %{SOURCE1006} .
 
 %build
 %if 0%{?sec_build_binary_debug_enable}
@@ -129,8 +143,10 @@ systemctl restart cynara.service
 %endif
 
 %post -n libaskuser-common -p /sbin/ldconfig
+%post -n libaskuser-notification -p /sbin/ldconfig
 
 %postun -n libaskuser-common -p /sbin/ldconfig
+%postun -n libaskuser-notification -p /sbin/ldconfig
 
 %files -n %{name}
 %manifest %{name}.manifest
@@ -147,6 +163,16 @@ systemctl restart cynara.service
 %license LICENSE
 %{_libdir}/libaskuser-common.so*
 
+%files -n libaskuser-notification
+%manifest libaskuser-notification.manifest
+%license LICENSE
+%{_libdir}/libaskuser-notification.so.*
+
+%files -n libaskuser-notification-devel
+%{_libdir}/libaskuser-notification.so
+%{_includedir}/askuser-notification
+%{_libdir}/pkgconfig/askuser-notification.pc
+
 %files -n askuser-plugins
 %manifest askuser-plugins.manifest
 %license LICENSE
@@ -164,4 +190,5 @@ systemctl restart cynara.service
 %license LICENSE
 %attr(755,root,root) /usr/bin/askuser-test
 %attr(755,root,root) /usr/bin/askuser-tests
+%attr(755,root,root) /usr/bin/askuser-notification-test
 
diff --git a/packaging/libaskuser-notification.manifest b/packaging/libaskuser-notification.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
index eef74f9c70870526988a17de38acbb2c82db663d..dfae210bb09f16b30b4aea29f7f89dfc26f9582a 100644 (file)
@@ -1,33 +1,67 @@
-SET(TARGET_PROTOCOL "protocol")
+# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    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        CMakeLists.txt
+# @author      Dariusz Michaluk <d.michaluk@samsung.com>
+#
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -ggdb -O0")
+SET(PROTOCOL_PATH ${ASKUSER_PATH}/common/protocol)
 
-INCLUDE_DIRECTORIES(
-    ${PROJECT_SOURCE_DIR}
-  )
+SET(ASKUSER_NOTIFICATION_VERSION_MAJOR 0)
+SET(ASKUSER_NOTIFICATION_VERSION ${ASKUSER_NOTIFICATION_VERSION_MAJOR}.1.0)
 
-SET(PROTOCOL_SOURCES
-    ${PROJECT_SOURCE_DIR}/channel.cpp
-    ${PROJECT_SOURCE_DIR}/ask-user-client.cpp
-    ${PROJECT_SOURCE_DIR}/sock.cpp
-    ${PROJECT_SOURCE_DIR}/ask-user-config.cpp
-  )
+SET(PC_FILE "askuser-notification.pc")
 
-ADD_LIBRARY(${TARGET_PROTOCOL} SHARED ${PROTOCOL_SOURCES})
+INCLUDE_DIRECTORIES(
+    ${PROTOCOL_PATH}
+  )
 
-TARGET_LINK_LIBRARIES(${TARGET_PROTOCOL})
+SET(ASKUSER_NOTIFICATION_SOURCES
+    ${PROTOCOL_PATH}/channel.cpp
+    ${PROTOCOL_PATH}/ask-user-client.cpp
+    ${PROTOCOL_PATH}/sock.cpp
+    ${PROTOCOL_PATH}/ask-user-config.cpp
+   )
 
+SET(ASKUSER_NOTIFICATION_TEST_SOURCES
+    ${PROTOCOL_PATH}/main.cpp
+   )
 
-SET(TARGET_PTEST "test")
+ADD_DEFINITIONS("-fvisibility=default")
 
-SET(TARGET_PTEST_SOURCES
-    ${PROJECT_SOURCE_DIR}/main.cpp
-  )
+ADD_LIBRARY(${TARGET_ASKUSER_NOTIFICATION_LIB} SHARED ${ASKUSER_NOTIFICATION_SOURCES})
+ADD_EXECUTABLE(${TARGET_ASKUSER_NOTIFICATION_TEST} ${ASKUSER_NOTIFICATION_TEST_SOURCES})
 
-ADD_EXECUTABLE(${TARGET_PTEST} ${TARGET_PTEST_SOURCES})
+SET_TARGET_PROPERTIES(${TARGET_ASKUSER_NOTIFICATION_LIB}
+    PROPERTIES
+        SOVERSION ${ASKUSER_NOTIFICATION_VERSION_MAJOR}
+        VERSION ${ASKUSER_NOTIFICATION_VERSION}
+    )
 
-TARGET_LINK_LIBRARIES(${TARGET_PTEST} ${TARGET_PROTOCOL})
+TARGET_LINK_LIBRARIES(${TARGET_ASKUSER_NOTIFICATION_LIB})
+TARGET_LINK_LIBRARIES(${TARGET_ASKUSER_NOTIFICATION_TEST} ${TARGET_ASKUSER_NOTIFICATION_LIB})
 
+INSTALL(TARGETS     ${TARGET_ASKUSER_NOTIFICATION_LIB}
+        DESTINATION ${LIB_INSTALL_DIR})
 
+CONFIGURE_FILE(${PC_FILE}.in ${PROTOCOL_PATH}/${PC_FILE} @ONLY)
+INSTALL(FILES       ${PROTOCOL_PATH}/${PC_FILE}
+        DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
+FILE(GLOB HEADERS   ${PROTOCOL_PATH}/askuser-notification/*.h)
+INSTALL(FILES       ${HEADERS}
+        DESTINATION ${INCLUDE_INSTALL_DIR}/askuser-notification)
 
+INSTALL(TARGETS     ${TARGET_ASKUSER_NOTIFICATION_TEST}
+        DESTINATION ${BIN_INSTALL_DIR})
index 4c77db9dc6c503b2655e0e71e8dce6b470677d29..b30f45c93e250361cb61d3761241ffac33938943 100644 (file)
 #include <vector>
 #include <memory>
 
-#include <ask-user/ask-user-client.h>
-#include <ask-user/ask-user-service.h>
+#include <askuser-notification/ask-user-client.h>
+#include <askuser-notification/ask-user-service.h>
 
 #include <ask-user-config.h>
 #include <sock.h>
 
+#define UNUSED __attribute__((unused))
+
 namespace AskUser {
 namespace Protocol {
 
@@ -71,11 +73,11 @@ int popup_launch(const std::string &pkgName,
     }
 }
 
-int popup_runtime(const std::string &pkgName,
-                  const std::string &appName,
-                  uid_t uid,
-                  std::string &privilege,
-                  int &result)
+int popup_runtime(UNUSED const std::string &pkgName,
+                  UNUSED const std::string &appName,
+                  UNUSED uid_t uid,
+                  UNUSED std::string &privilege,
+                  UNUSED int &result)
 {
     return -1;
 }
diff --git a/src/common/protocol/ask-user/ask-user-client.h b/src/common/protocol/ask-user/ask-user-client.h
deleted file mode 100644 (file)
index 15b9e44..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- *  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        ask-user-client.h
- * @author      Bartlomiej Grzelewski <b.grzelewski@samsung.com>
- * @brief
- */
-#pragma once
-
-#include <sys/types.h>
-
-#include <string>
-#include <vector>
-#include <memory>
-#include <ask-user/ask-user-types.h>
-
-namespace AskUser {
-namespace Protocol {
-/**
- * Synchronous request for showing popup.
- *
- * \param[in] pkgName    Application package name.
- * \param[in] appName    Application name.
- * \param[in] uid        Information about user that should see popup.
- * \param[in] privileges List of privileges that should be shown to user.
- * \param[out] result    Result returned by ask-user application.
- *
- * \return Value less that 0 means ipc error.
- */
- int popup_launch(const std::string &pkgName, const std::string &appName, uid_t uid, const PrivilegeVector &privileges, int &result);
-
- /**
-  * Synchronous request for showing popup.
-  *
-  * \param[in] pkgName    Application package name.
-  * \param[in] appName    Application name.
-  * \param[in] uid        Information about user that should see popup.
-  * \param[in] privilege  Privilege that should be shown to user.
-  * \param[out] result    Result returned by ask-user application.
-  *
-  * \return Value less that 0 means ipc error.
-  */
- int popup_runtime(const std::string &pkgName, const std::string &appName, uid_t uid, std::string &privilege, int &result);
-
-/**
- * Nonblocking request for showing toast.
- *
- * \param[in] pkgName    Application package name.
- * \param[in] appName    Application name.
- * \param[in] uid        Information about user that should see popup.
- * \param[in] privilege  Name of privilege that was denied.
- *
- * \return Value less that 0 means ipc error.
- */
-int toast_deny(const std::string &pkgName, const std::string &appName, uid_t uid, const std::string &privilege);
-
-/**
- * Nonblocking request for showing toast.
- *
- * \param[in] pkgName    Application package name.
- * \param[in] appName    Application name.
- * \param[in] uid        Information about user that should see popup.
- *
- * \return Value less that 0 means ipc error.
- */
-int toast_fail_launch(const std::string &pkgName, const std::string &appName, uid_t uid);
-
-} // namespace Protocol
-} // namespace AskUser
-
diff --git a/src/common/protocol/ask-user/ask-user-service.h b/src/common/protocol/ask-user/ask-user-service.h
deleted file mode 100644 (file)
index ca9b704..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *  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        ask-user-service.h
- * @author      Bartlomiej Grzelewski <b.grzelewski@samsung.com>
- * @brief
- */
-#pragma once
-
-#include <sys/types.h>
-
-#include <string>
-#include <vector>
-#include <memory>
-
-#include <ask-user/ask-user-types.h>
-
-namespace AskUser {
-namespace Protocol {
-
-enum FdMask {
-    READ = 1,
-    WRITE = 2,
-};
-
-/**
- * IServiceCallbacks defines set of callbacks that must be implemented in service.
- */
-
-struct IServerCallbacks {
-
-    virtual ~IServerCallbacks(){}
-    /**
-     * This function gives you number of descriptor that should be watched by poll/select.
-     *
-     * \param[in] fd   Number of opened descriptor.
-     * \param[in] mask Type of acction that is required on this descriptor.
-     *           mask == 0 remove descriptor fd from watched pool
-     *           mask == 1 watch descriptor for READ
-     *           mask == 2 watch descriptor for WRITE
-     *           maks == 3 watch descriptor for READ and WRITE
-     */
-    virtual void updateFd(int fd, int mask) = 0;
-    /**
-     * some client called popup function with parameters.
-     */
-    virtual void popup_launch(int requestId, const std::string &pkgName, const std::string &appName, uid_t uid, const PrivilegeVector &privileges) = 0;
-    /**
-     * some client called test_deny function with parameters.
-     */
-     virtual void toast_deny(const std::string &pkgName, const std::string &appName, uid_t uid, const Privilege &privilege) = 0;
-    /**
-     * some client called toast_fail_launch function with parameters.
-     */
-     virtual void toast_fail_launch(const std::string &pkgName, const std::string &appName, uid_t uid) = 0;
-};
-
-struct IChannel {
-    virtual ~IChannel(){}
-
-    /**
-     * Process function should be called each time some event is reported by poll/select on
-     * descriptor.
-     *
-     * \param[in] fd    Number of descriptor.
-     * \param[in] mask  Information about event that is waiting on descriptor
-     *                 (FdMask::READ or FdMask::WRITE). If you pass 0 for some reason
-     *                 the descriptor will be closed and callback updateFd will be called
-     *                 with mask = 0
-     */
-    virtual void process(int fd, int mask) = 0;
-
-    /**
-     * Information about action that was choosed by user.
-     *
-     * \param[in] requestId  Request number.
-     * \param[in] response   Information about action choosed by user.
-     */
-    virtual void popupResponse(int requestId, int response) = 0;
-};
-
-typedef std::unique_ptr<IChannel> ChannelPtr;
-typedef std::unique_ptr<IServerCallbacks> ServerCallbacksPtr;
-
-ChannelPtr createChannel(ServerCallbacksPtr ptr);
-
-} // namespace Protocol
-} // namespace AskUser
-
diff --git a/src/common/protocol/ask-user/ask-user-types.h b/src/common/protocol/ask-user/ask-user-types.h
deleted file mode 100644 (file)
index 642667c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  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        ask-user-types.h
- * @author      Bartlomiej Grzelewski <b.grzelewski@samsung.com>
- * @brief
- */
-#pragma once
-
-#define ASKUSER_DENY_ONCE 0
-#define ASKUSER_DENY_FOREVER 1
-#define ASKUSER_ALLOW_ONCE 2
-#define ASKUSER_ALLOW_FOREVER 3
-#define ASKUSER_UNKNOWN_ERROR -255
-
-namespace AskUser {
-namespace Protocol {
-
-typedef std::string Privilege;
-typedef std::vector<Privilege> PrivilegeVector;
-
-} // namespace Protocol
-} // AskUser
-
diff --git a/src/common/protocol/askuser-notification.pc.in b/src/common/protocol/askuser-notification.pc.in
new file mode 100644 (file)
index 0000000..dca3398
--- /dev/null
@@ -0,0 +1,12 @@
+# Package Information for pkg-config
+
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: askuser-notification
+Description: askuser-notification library
+Version: @ASKUSER_NOTIFICATION_VERSION@
+Libs: -L${libdir} -laskuser-notification
+Cflags: -I${includedir}/askuser-notification
diff --git a/src/common/protocol/askuser-notification/ask-user-client.h b/src/common/protocol/askuser-notification/ask-user-client.h
new file mode 100644 (file)
index 0000000..a98602f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  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        ask-user-client.h
+ * @author      Bartlomiej Grzelewski <b.grzelewski@samsung.com>
+ * @brief
+ */
+#pragma once
+
+#include <sys/types.h>
+
+#include <string>
+#include <vector>
+#include <memory>
+#include <askuser-notification/ask-user-types.h>
+
+namespace AskUser {
+namespace Protocol {
+/**
+ * Synchronous request for showing popup.
+ *
+ * \param[in] pkgName    Application package name.
+ * \param[in] appName    Application name.
+ * \param[in] uid        Information about user that should see popup.
+ * \param[in] privileges List of privileges that should be shown to user.
+ * \param[out] result    Result returned by ask-user application.
+ *
+ * \return Value less that 0 means ipc error.
+ */
+ int popup_launch(const std::string &pkgName, const std::string &appName, uid_t uid, const PrivilegeVector &privileges, int &result);
+
+ /**
+  * Synchronous request for showing popup.
+  *
+  * \param[in] pkgName    Application package name.
+  * \param[in] appName    Application name.
+  * \param[in] uid        Information about user that should see popup.
+  * \param[in] privilege  Privilege that should be shown to user.
+  * \param[out] result    Result returned by ask-user application.
+  *
+  * \return Value less that 0 means ipc error.
+  */
+ int popup_runtime(const std::string &pkgName, const std::string &appName, uid_t uid, std::string &privilege, int &result);
+
+/**
+ * Nonblocking request for showing toast.
+ *
+ * \param[in] pkgName    Application package name.
+ * \param[in] appName    Application name.
+ * \param[in] uid        Information about user that should see popup.
+ * \param[in] privilege  Name of privilege that was denied.
+ *
+ * \return Value less that 0 means ipc error.
+ */
+int toast_deny(const std::string &pkgName, const std::string &appName, uid_t uid, const std::string &privilege);
+
+/**
+ * Nonblocking request for showing toast.
+ *
+ * \param[in] pkgName    Application package name.
+ * \param[in] appName    Application name.
+ * \param[in] uid        Information about user that should see popup.
+ *
+ * \return Value less that 0 means ipc error.
+ */
+int toast_fail_launch(const std::string &pkgName, const std::string &appName, uid_t uid);
+
+} // namespace Protocol
+} // namespace AskUser
+
diff --git a/src/common/protocol/askuser-notification/ask-user-service.h b/src/common/protocol/askuser-notification/ask-user-service.h
new file mode 100644 (file)
index 0000000..3761d07
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  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        ask-user-service.h
+ * @author      Bartlomiej Grzelewski <b.grzelewski@samsung.com>
+ * @brief
+ */
+#pragma once
+
+#include <sys/types.h>
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include <askuser-notification/ask-user-types.h>
+
+namespace AskUser {
+namespace Protocol {
+
+enum FdMask {
+    READ = 1,
+    WRITE = 2,
+};
+
+/**
+ * IServiceCallbacks defines set of callbacks that must be implemented in service.
+ */
+
+struct IServerCallbacks {
+
+    virtual ~IServerCallbacks(){}
+    /**
+     * This function gives you number of descriptor that should be watched by poll/select.
+     *
+     * \param[in] fd   Number of opened descriptor.
+     * \param[in] mask Type of acction that is required on this descriptor.
+     *           mask == 0 remove descriptor fd from watched pool
+     *           mask == 1 watch descriptor for READ
+     *           mask == 2 watch descriptor for WRITE
+     *           maks == 3 watch descriptor for READ and WRITE
+     */
+    virtual void updateFd(int fd, int mask) = 0;
+    /**
+     * some client called popup function with parameters.
+     */
+    virtual void popup_launch(int requestId, const std::string &pkgName, const std::string &appName, uid_t uid, const PrivilegeVector &privileges) = 0;
+    /**
+     * some client called test_deny function with parameters.
+     */
+     virtual void toast_deny(const std::string &pkgName, const std::string &appName, uid_t uid, const Privilege &privilege) = 0;
+    /**
+     * some client called toast_fail_launch function with parameters.
+     */
+     virtual void toast_fail_launch(const std::string &pkgName, const std::string &appName, uid_t uid) = 0;
+};
+
+struct IChannel {
+    virtual ~IChannel(){}
+
+    /**
+     * Process function should be called each time some event is reported by poll/select on
+     * descriptor.
+     *
+     * \param[in] fd    Number of descriptor.
+     * \param[in] mask  Information about event that is waiting on descriptor
+     *                 (FdMask::READ or FdMask::WRITE). If you pass 0 for some reason
+     *                 the descriptor will be closed and callback updateFd will be called
+     *                 with mask = 0
+     */
+    virtual void process(int fd, int mask) = 0;
+
+    /**
+     * Information about action that was choosed by user.
+     *
+     * \param[in] requestId  Request number.
+     * \param[in] response   Information about action choosed by user.
+     */
+    virtual void popupResponse(int requestId, int response) = 0;
+};
+
+typedef std::unique_ptr<IChannel> ChannelPtr;
+typedef std::unique_ptr<IServerCallbacks> ServerCallbacksPtr;
+
+ChannelPtr createChannel(ServerCallbacksPtr ptr);
+
+} // namespace Protocol
+} // namespace AskUser
+
diff --git a/src/common/protocol/askuser-notification/ask-user-types.h b/src/common/protocol/askuser-notification/ask-user-types.h
new file mode 100644 (file)
index 0000000..642667c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  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        ask-user-types.h
+ * @author      Bartlomiej Grzelewski <b.grzelewski@samsung.com>
+ * @brief
+ */
+#pragma once
+
+#define ASKUSER_DENY_ONCE 0
+#define ASKUSER_DENY_FOREVER 1
+#define ASKUSER_ALLOW_ONCE 2
+#define ASKUSER_ALLOW_FOREVER 3
+#define ASKUSER_UNKNOWN_ERROR -255
+
+namespace AskUser {
+namespace Protocol {
+
+typedef std::string Privilege;
+typedef std::vector<Privilege> PrivilegeVector;
+
+} // namespace Protocol
+} // AskUser
+
index 7b7e7266aba8a629ad682a630b207f6a1aa582c0..657252c949087122f1781585c4bb41462dc91a3d 100644 (file)
@@ -21,7 +21,7 @@
 #include <sstream>
 #include <string>
 
-#include <ask-user/ask-user-service.h>
+#include <askuser-notification/ask-user-service.h>
 
 #include <ask-user-config.h>
 #include <channel.h>
index 8898155bdd6be1322990c77fcf2a33352cd2d87d..627ef11d7867a8314d6d71967352a21aa0d6ae42 100644 (file)
@@ -25,7 +25,8 @@
 #include <string>
 #include <vector>
 
-#include <ask-user/ask-user-service.h>
+#include <askuser-notification/ask-user-service.h>
+
 #include <raw-buffer.h>
 #include <sock.h>
 
index d733494cd7503257a5d4e6961b35767e32eee57a..3eee6fc2535591ed8723c4832c994c02c09f346b 100644 (file)
 #include <poll.h>
 #include <unistd.h>
 
-#include <ask-user/ask-user-client.h>
-#include <ask-user/ask-user-service.h>
+#include <askuser-notification/ask-user-client.h>
+#include <askuser-notification/ask-user-service.h>
 
 std::map<int, int> m_sockets;
 
+#define UNUSED __attribute__((unused))
+
 using namespace AskUser::Protocol;
 
 struct Callbacks : public IServerCallbacks {
@@ -42,13 +44,13 @@ struct Callbacks : public IServerCallbacks {
         m_sockets[fd] = mask;
     }
 
-    virtual void popup_launch(int requestId, const std::string &pkgName, const std::string &appName, uid_t uid, const PrivilegeVector &priv) {
+    virtual void popup_launch(int requestId, const std::string &pkgName, const std::string &appName, uid_t uid, UNUSED const PrivilegeVector &priv) {
         printf("call popup %s %s %d\n", pkgName.c_str(), appName.c_str(), uid);
         if (m_channel)
             m_channel->popupResponse(requestId, 0xdeadbeef);
     }
 
-    virtual void toast_deny(const std::string &pkgName, const std::string &appName, uid_t uid, const Privilege &privilege) {
+    virtual void toast_deny(const std::string &pkgName, const std::string &appName, uid_t uid, UNUSED const Privilege &privilege) {
         printf("call toast_deny %s %s %d\n", pkgName.c_str(), appName.c_str(), uid);
     }
 
@@ -95,7 +97,7 @@ void server(void) {
 void stream() {
     PrivilegeVector vect = {"one", "two"};
     int result;
-    int ret = popup_launch("spkg", "sapp", getuid(), vect, result);
+    UNUSED int ret = popup_launch("spkg", "sapp", getuid(), vect, result);
     printf("Sended stream. Result: %x\n", result);
 }
 
@@ -112,7 +114,7 @@ void toust2() {
 int main(){
     int com;
     printf("0 - server, 1 - send stream, 2 - send toust1, 3 - send toust2\n>");
-    scanf("%d", &com);
+    UNUSED int ret = scanf("%d", &com);
 
     switch(com) {
     case 0:
index cde563a28ab008ae728a38f1067c7ec2f4728422..18b65b472b68c54b68262b2ef5b3cc6d51e26b3e 100644 (file)
@@ -31,7 +31,7 @@
 #include <string>
 #include <vector>
 
-#include <ask-user/ask-user-service.h>
+#include <askuser-notification/ask-user-service.h>
 
 #include <sock.h>
 
@@ -218,7 +218,7 @@ int Sock::send(const RawBuffer &buffer) {
 }
 
 int Sock::wait(int mask) {
-    pollfd fd = {};
+    pollfd fd = {0, 0, 0};
 
     fd.fd = m_fd;
     fd.events = (mask & FdMask::READ ? POLLIN : 0) | (mask & FdMask::WRITE ? POLLOUT : 0);