2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bumjin Im <bj.im@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @file client-common.h
20 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 * @brief This file contains implementation of common types
23 * used in Central Key Manager.
26 #ifndef _KEY_MANAGER_CLIENT_
27 #define _KEY_MANAGER_CLIENT_
34 #include <noncopyable.h>
35 #include <ckm/ckm-type.h>
36 #include <ckmc/ckmc-error.h>
37 #include <message-buffer.h>
38 #include <protocols.h>
40 #define EXCEPTION_GUARD_START_CPPAPI return CKM::try_catch([&]()->int {
41 #define EXCEPTION_GUARD_START_CAPI return CKM::try_catch_enclosure([&]()->int {
42 #define EXCEPTION_GUARD_END });
52 AliasSupport(const Alias &alias);
54 const ClientId &getOwner() const;
55 const Name &getName() const;
56 bool isOwnerEmpty() const;
58 static Alias merge(const ClientId &owner, const Name &alias);
69 NONCOPYABLE(SockRAII);
73 int connect(const char *interface);
75 bool isConnected() const;
77 int waitForSocket(int event, int timeout);
80 int connectWrapper(int socket, const char *interface);
84 class ServiceConnection {
86 ServiceConnection(const char *service_interface);
88 // roundtrip: send and receive
89 int processRequest(const CKM::RawBuffer &send_buf,
90 CKM::MessageBuffer &recv_buf);
93 int send(const CKM::RawBuffer &send_buf);
94 int receive(CKM::MessageBuffer &recv_buf);
96 virtual ~ServiceConnection();
99 int prepareConnection();
102 std::string m_serviceInterface;
106 * Decorator function that performs frequently repeated exception handling in
107 * SS client API functions. Accepts lambda expression as an argument.
110 int try_catch(const std::function<int()> &func);
112 int try_catch_enclosure(const std::function<int()> &func);
114 // for c++ async api layer
115 void try_catch_async(const std::function<void()> &func,
116 const std::function<void(int)> &error);
120 #endif // _KEY_MANAGER_CLIENT_