Adding an example service for key-manager.
Change-Id: I72b30bed332785683fb104850a11b61c062ba8d1
mkdir -p %{buildroot}/usr/lib/systemd/system/multi-user.target.wants
mkdir -p %{buildroot}/usr/lib/systemd/system/sockets.target.wants
ln -s ../key-manager.service %{buildroot}/usr/lib/systemd/system/multi-user.target.wants/key-manager.service
+ln -s ../key-manager-echo.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/key-manager-echo.socket
%clean
rm -rf %{buildroot}
%attr(-,root,root) /usr/lib/systemd/system/multi-user.target.wants/key-manager.service
%attr(-,root,root) /usr/lib/systemd/system/key-manager.service
%attr(-,root,root) /usr/lib/systemd/system/key-manager.target
+%attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/key-manager-echo.socket
+%attr(-,root,root) /usr/lib/systemd/system/key-manager-echo.socket
%{_datadir}/license/%{name}
%files -n libkey-manager-client
${KEY_MANAGER_PATH}/main/generic-socket-manager.cpp
${KEY_MANAGER_PATH}/main/socket-manager.cpp
${KEY_MANAGER_PATH}/main/key-manager-main.cpp
+ ${KEY_MANAGER_PATH}/service/echo.cpp
)
SET_SOURCE_FILES_PROPERTIES(
SET(KEY_MANAGER_CLIENT_SOURCES
${KEY_MANAGER_CLIENT_SRC_PATH}/client-common.cpp
+ ${KEY_MANAGER_CLIENT_SRC_PATH}/client-echo.cpp
)
ADD_LIBRARY(${TARGET_KEY_MANAGER_CLIENT} SHARED ${KEY_MANAGER_CLIENT_SOURCES})
extern "C" {
#endif
+/*
+ * This function was created mainly for testing key-manager client/service
+ * proper behaviour. It sends a message and returns message from service,
+ * which should be a pure echo.
+ *
+ * \param[in] Message for service
+ * \param[out] Response from service
+ *
+ * \return KEY_MANAGER_API_ERROR_INPUT_PARAM when trying to pass NULL message
+ * \return KEY_MANAGER_API_SUCCESS on success
+ */
+int key_manager_echo(const char* echo, char** oche);
#ifdef __cplusplus
--- /dev/null
+/* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Bumjin Im <bj.im@samsung.com>
+ *
+ * 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 client-echo.cpp
+ * @author Zofia Abramowska (z.abramowska@samsung.com)
+ * @version 1.0
+ * @version This file contains example of key-manager client implementation
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+
+#include <message-buffer.h>
+#include <client-common.h>
+#include <protocols.h>
+
+#include <key-manager.h>
+
+KEY_MANAGER_API
+int key_manager_echo(const char *echo, char** oche) {
+ using namespace CentralKeyManager;
+
+ if(echo == NULL){
+ LogDebug("Echo message is null");
+ return KEY_MANAGER_API_ERROR_INPUT_PARAM;
+ }
+
+ MessageBuffer send, recv;
+ Serialization::Serialize(send, std::string(echo));
+
+ int retCode = sendToServer(SERVICE_SOCKET_ECHO, send.Pop(), recv);
+
+ if(retCode != KEY_MANAGER_API_SUCCESS)
+ return retCode;
+
+ std::string response;
+ Deserialization::Deserialize(recv, response);
+
+ *oche = strdup(response.c_str());
+
+ return KEY_MANAGER_API_SUCCESS;
+}
namespace CentralKeyManager {
-
+ char const * const SERVICE_SOCKET_ECHO =
+ "/tmp/.key-manager-api-echo.sock";
} // namespace CentralKeyManager
namespace CentralKeyManager {
+ extern char const * const SERVICE_SOCKET_ECHO;
} // namespace CentralKeyManager
#include <socket-manager.h>
+#include <echo.h>
+
IMPLEMENT_SAFE_SINGLETON(CentralKeyManager::Log::LogSystem);
#define REGISTER_SOCKET_SERVICE(manager, service) \
LogInfo("Start!");
CentralKeyManager::SocketManager manager;
+ auto echoService = new CentralKeyManager::EchoService;
+ echoService->Create();
+ manager.RegisterSocketService(echoService);
+
manager.MainLoop();
}
UNHANDLED_EXCEPTION_HANDLER_END
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Bumjin Im <bj.im@samsung.com>
+ *
+ * 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 server-main2.h
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version 1.0
+ * @brief Implementation of sample service.
+ */
+
+#include <dpl/log/log.h>
+
+#include <protocols.h>
+#include <echo.h>
+
+namespace CentralKeyManager {
+
+GenericSocketService::ServiceDescriptionVector EchoService::GetServiceDescription() {
+ return ServiceDescriptionVector {{SERVICE_SOCKET_ECHO, "*"}};
+}
+
+void EchoService::accept(const AcceptEvent &event) {
+ LogDebug("Accept event. ConnectionID: " << event.connectionID.sock
+ << " ServiceID: " << event.interfaceID);
+}
+
+void EchoService::write(const WriteEvent &event) {
+ LogDebug("WriteEvent. ConnectionID: " << event.connectionID.sock <<
+ " Size: " << event.size << " Left: " << event.left);
+ if (event.left == 0)
+ m_serviceManager->Close(event.connectionID);
+}
+
+void EchoService::process(const ReadEvent &event) {
+ LogDebug("ReadEvent. ConnectionID: " << event.connectionID.sock <<
+ " Buffer size: " << event.rawBuffer.size());
+ m_serviceManager->Write(event.connectionID, event.rawBuffer);
+ LogDebug("Write completed");
+}
+
+void EchoService::close(const CloseEvent &event) {
+ LogDebug("CloseEvent. ConnectionID: " << event.connectionID.sock);
+}
+
+} // namespace CentralKeyManager
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Bumjin Im <bj.im@samsung.com>
+ *
+ * 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 echo.h
+ * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
+ * @version 1.0
+ * @brief Sample service implementation.
+ */
+
+#ifndef _SECURITY_SERVER_ECHO_
+#define _SECURITY_SERVER_ECHO_
+
+#include <service-thread.h>
+#include <generic-socket-manager.h>
+
+#include <dpl/serialization.h>
+
+#include <message-buffer.h>
+
+namespace CentralKeyManager {
+
+class EchoService
+ : public CentralKeyManager::GenericSocketService
+ , public CentralKeyManager::ServiceThread<EchoService>
+{
+public:
+ ServiceDescriptionVector GetServiceDescription();
+
+ DECLARE_THREAD_EVENT(AcceptEvent, accept)
+ DECLARE_THREAD_EVENT(WriteEvent, write)
+ DECLARE_THREAD_EVENT(ReadEvent, process)
+ DECLARE_THREAD_EVENT(CloseEvent, close)
+
+ void accept(const AcceptEvent &event);
+ void write(const WriteEvent &event);
+ void process(const ReadEvent &event);
+ void close(const CloseEvent &event);
+};
+
+} // namespace CentralKeyManager
+
+#endif // _SECURITY_SERVER_ECHO_
INSTALL(FILES
${CMAKE_SOURCE_DIR}/systemd/key-manager.service
${CMAKE_SOURCE_DIR}/systemd/key-manager.target
+ ${CMAKE_SOURCE_DIR}/systemd/key-manager-echo.socket
DESTINATION
/usr/lib/systemd/system
)
--- /dev/null
+[Socket]
+ListenStream=/tmp/.key-manager-api-echo.sock
+SockMode=0777
+SmackLabelIpIn=*
+SmackLabelIpOut=@
+
+Service=key-manager.service
+
+[Unit]
+Wants=key-manager.service
+Before=key-manager.service
+
+[Install]
+WantedBy=sockets.target
[Service]
Type=notify
ExecStart=/usr/bin/key-manager
+Sockets=key-manager-echo.socket
[Install]
WantedBy=multi-user.target