2 * Copyright (c) 2000 - 2019 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 * @file client-common.h
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief This file contains implementation of common types
21 * used in Central Key Manager.
24 #ifndef _KEY_MANAGER_CLIENT_
25 #define _KEY_MANAGER_CLIENT_
32 #include <noncopyable.h>
33 #include <ckm/ckm-type.h>
34 #include <ckmc/ckmc-error.h>
35 #include <message-buffer.h>
36 #include <protocols.h>
38 #define EXCEPTION_GUARD_START_CPPAPI return CKM::try_catch([&]()->int {
39 #define EXCEPTION_GUARD_START_CAPI return CKM::try_catch_enclosure([&]()->int {
40 #define EXCEPTION_GUARD_END });
45 struct ckmc_alias_info_s {
47 bool is_password_protected;
56 AliasSupport(const Alias &alias);
58 const ClientId &getOwner() const;
59 const Name &getName() const;
60 bool isOwnerEmpty() const;
62 static Alias merge(const ClientId &owner, const Name &alias);
73 NONCOPYABLE(SockRAII);
77 int connect(const char *interface);
79 bool isConnected() const;
81 int waitForSocket(int event, int timeout);
84 int connectWrapper(int socket, const char *interface);
88 class ServiceConnection {
90 ServiceConnection(const char *service_interface);
92 // roundtrip: send and receive
93 int processRequest(const CKM::RawBuffer &send_buf,
94 CKM::MessageBuffer &recv_buf);
97 int send(const CKM::RawBuffer &send_buf);
98 int receive(CKM::MessageBuffer &recv_buf);
100 virtual ~ServiceConnection();
103 int prepareConnection();
106 std::string m_serviceInterface;
110 * Decorator function that performs frequently repeated exception handling in
111 * SS client API functions. Accepts lambda expression as an argument.
114 int try_catch(const std::function<int()> &func);
116 int try_catch_enclosure(const std::function<int()> &func);
118 // for c++ async api layer
119 void try_catch_async(const std::function<void()> &func,
120 const std::function<void(int)> &error);
124 #endif // _KEY_MANAGER_CLIENT_