-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
142 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
#ifndef OCVSMD_SDK_DAEMON_HPP_INCLUDED | ||
#define OCVSMD_SDK_DAEMON_HPP_INCLUDED | ||
|
||
#include <memory> | ||
|
||
namespace ocvsmd | ||
{ | ||
namespace sdk | ||
{ | ||
|
||
/// An abstract factory for the specialized interfaces. | ||
/// | ||
class Daemon | ||
{ | ||
public: | ||
static std::unique_ptr<Daemon> make(); | ||
|
||
Daemon(Daemon&&) = delete; | ||
Daemon(const Daemon&) = delete; | ||
Daemon& operator=(Daemon&&) = delete; | ||
Daemon& operator=(const Daemon&) = delete; | ||
|
||
virtual ~Daemon() = default; | ||
|
||
virtual void send_messages() const = 0; | ||
|
||
protected: | ||
Daemon() = default; | ||
|
||
}; // Daemon | ||
|
||
} // namespace sdk | ||
} // namespace ocvsmd | ||
|
||
#endif // OCVSMD_SDK_DAEMON_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.27) | ||
|
||
add_library(ocvsmd_sdk | ||
daemon.cpp | ||
) | ||
target_link_libraries(ocvsmd_sdk | ||
PRIVATE ocvsmd_common | ||
) | ||
target_include_directories(ocvsmd_sdk | ||
PUBLIC ${include_dir} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
#include <ocvsmd/sdk/daemon.hpp> | ||
|
||
#include "ipc/unix_socket_client.hpp" | ||
|
||
#include <memory> | ||
#include <utility> | ||
#include <unistd.h> | ||
|
||
namespace ocvsmd | ||
{ | ||
namespace sdk | ||
{ | ||
namespace | ||
{ | ||
|
||
class DaemonImpl final : public Daemon | ||
{ | ||
public: | ||
bool connect() | ||
{ | ||
return ipc_client_.connect_to_server(); | ||
} | ||
|
||
void send_messages() const override | ||
{ | ||
ipc_client_.send_message("Hello, world!"); | ||
::sleep(1); | ||
ipc_client_.send_message("Goodbye, world!"); | ||
::sleep(1); | ||
} | ||
|
||
private: | ||
common::ipc::UnixSocketClient ipc_client_{"/var/run/ocvsmd/local.sock"}; | ||
|
||
}; // DaemonImpl | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<Daemon> Daemon::make() | ||
{ | ||
auto daemon = std::make_unique<DaemonImpl>(); | ||
if (!daemon->connect()) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
return std::move(daemon); | ||
} | ||
|
||
} // namespace sdk | ||
} // namespace ocvsmd |