/*
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact: Bumjin Im <bj.im@samsung.com>
+ * Copyright (c) 2000 - 2019 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.
* @file client-common.h
* @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
* @version 1.0
- * @brief This file constains implementation of common types
+ * @brief This file contains implementation of common types
* used in Central Key Manager.
*/
#ifndef _KEY_MANAGER_CLIENT_
#define _KEY_MANAGER_CLIENT_
+#include <unistd.h>
+
#include <vector>
#include <functional>
#include <noncopyable.h>
#include <ckm/ckm-type.h>
+#include <ckmc/ckmc-error.h>
#include <message-buffer.h>
#include <protocols.h>
-#define KEY_MANAGER_API __attribute__((visibility("default")))
+#define EXCEPTION_GUARD_START_CPPAPI return CKM::try_catch([&]()->int {
+#define EXCEPTION_GUARD_START_CAPI return CKM::try_catch_enclosure([&]()->int {
+#define EXCEPTION_GUARD_END });
extern "C" {
- struct msghdr;
+ struct msghdr;
+
+ struct ckmc_alias_info_s {
+ char* alias;
+ bool is_password_protected;
+ };
+
}
namespace CKM {
-class AliasSupport
-{
- public:
- AliasSupport(const Alias &alias);
+class AliasSupport {
+public:
+ AliasSupport(const Alias &alias);
- const Label & getLabel() const;
- const Name & getName() const;
- bool isLabelEmpty() const;
+ const ClientId &getOwner() const;
+ const Name &getName() const;
+ bool isOwnerEmpty() const;
- static Alias merge(const Label &label, const Name &alias);
- private:
- Name m_name;
- Label m_label;
+ static Alias merge(const ClientId &owner, const Name &alias);
+
+private:
+ Name m_name;
+ ClientId m_owner;
};
class SockRAII {
- public:
- SockRAII();
-
- NONCOPYABLE(SockRAII);
+public:
+ SockRAII();
- virtual ~SockRAII();
+ NONCOPYABLE(SockRAII);
- int Connect(char const * const interface);
- void Disconnect();
- bool isConnected() const;
- int Get() const;
+ virtual ~SockRAII();
- protected:
- int WaitForSocket(int event, int timeout);
+ int connect(const char *interface);
+ void disconnect();
+ bool isConnected() const;
+ int get() const;
+ int waitForSocket(int event, int timeout);
- private:
- int m_sock;
+protected:
+ int connectWrapper(int socket, const char *interface);
+ int m_sock;
};
-class ServiceConnection : public SockRAII
-{
- public:
- ServiceConnection(char const * const service_interface);
+class ServiceConnection {
+public:
+ ServiceConnection(const char *service_interface);
- // roundtrip: send and receive
- int processRequest(const CKM::RawBuffer &send_buf,
- CKM::MessageBuffer &recv_buf);
+ // roundtrip: send and receive
+ int processRequest(const CKM::RawBuffer &send_buf,
+ CKM::MessageBuffer &recv_buf);
- // blocking
- int send(const CKM::RawBuffer &send_buf);
- int receive(CKM::MessageBuffer &recv_buf);
+ // blocking
+ int send(const CKM::RawBuffer &send_buf);
+ int receive(CKM::MessageBuffer &recv_buf);
- virtual ~ServiceConnection();
+ virtual ~ServiceConnection();
- private:
- std::string m_service_interface;
+protected:
+ int prepareConnection();
- int Connect();
+ SockRAII m_socket;
+ std::string m_serviceInterface;
};
-
/*
* Decorator function that performs frequently repeated exception handling in
* SS client API functions. Accepts lambda expression as an argument.
*/
-int try_catch(const std::function<int()>& func);
-
-void try_catch_async(const std::function<void()>& func, const std::function<void(int)>& error);
+// for c++ api layer
+int try_catch(const std::function<int()> &func);
+// for c api layer
+int try_catch_enclosure(const std::function<int()> &func);
+
+// for c++ async api layer
+void try_catch_async(const std::function<void()> &func,
+ const std::function<void(int)> &error);
} // namespace CKM