}
if (std::is_same<T, Policy<int>>::value && key == "value")
- return static_cast<Member>(Stringfy::Restore(value));
+ return static_cast<Member>(Stringify::Restore(value));
try {
return boost::lexical_cast<Member>(value);
namespace vist {
-Stringfy::Stringfy(int origin) noexcept :
+Stringify::Stringify(int origin) noexcept :
type(Type::Integer), buffer(convert(origin))
{
}
-Stringfy::Stringfy(const std::string& origin) noexcept :
+Stringify::Stringify(const std::string& origin) noexcept :
type(Type::String), buffer(convert(origin))
{
}
-Stringfy Stringfy::Restore(const std::string& dumped)
+Stringify Stringify::Restore(const std::string& dumped)
{
- auto parsed = Stringfy::Parse(dumped);
+ auto parsed = Stringify::Parse(dumped);
switch (parsed.first) {
case Type::Integer:
- return Stringfy(std::stoi(parsed.second));
+ return Stringify(std::stoi(parsed.second));
case Type::String:
- return Stringfy(parsed.second);
+ return Stringify(parsed.second);
case Type::None:
default:
THROW(ErrCode::LogicError) << "Invalid format.";
}
}
-Stringfy::Type Stringfy::GetType(const std::string& dumped)
+Stringify::Type Stringify::GetType(const std::string& dumped)
{
- return Stringfy::Parse(dumped).first;
+ return Stringify::Parse(dumped).first;
}
-Stringfy::operator std::string() const
+Stringify::operator std::string() const
{
- auto parsed = Stringfy::Parse(this->buffer);
+ auto parsed = Stringify::Parse(this->buffer);
if (parsed.first != Type::String)
THROW(ErrCode::TypeUnsafed) << "Type is not safed.";
return parsed.second;
}
-Stringfy::operator int() const
+Stringify::operator int() const
{
- auto parsed = Stringfy::Parse(this->buffer);
+ auto parsed = Stringify::Parse(this->buffer);
if (parsed.first != Type::Integer)
THROW(ErrCode::TypeUnsafed) << "Type is not safed.";
return std::stoi(parsed.second);
}
-std::pair<Stringfy::Type, std::string> Stringfy::Parse(const std::string& dumped)
+std::pair<Stringify::Type, std::string> Stringify::Parse(const std::string& dumped)
{
std::string type = dumped.substr(0, dumped.find('/'));
std::string data = dumped.substr(dumped.find('/') + 1);
return std::make_pair(static_cast<Type>(type.at(0)), data);
}
-std::string Stringfy::dump() const noexcept
+std::string Stringify::dump() const noexcept
{
return this->buffer;
}
using namespace vist;
-TEST(StringfyTests, integer_dump)
+TEST(StringifyTests, integer_dump)
{
- EXPECT_EQ("I/-11", Stringfy::Dump(-11));
- EXPECT_EQ("I/-1", Stringfy::Dump(-1));
- EXPECT_EQ("I/0", Stringfy::Dump(0));
- EXPECT_EQ("I/1", Stringfy::Dump(1));
- EXPECT_EQ("I/11", Stringfy::Dump(11));
+ EXPECT_EQ("I/-11", Stringify::Dump(-11));
+ EXPECT_EQ("I/-1", Stringify::Dump(-1));
+ EXPECT_EQ("I/0", Stringify::Dump(0));
+ EXPECT_EQ("I/1", Stringify::Dump(1));
+ EXPECT_EQ("I/11", Stringify::Dump(11));
}
-TEST(StringfyTests, string_dump)
+TEST(StringifyTests, string_dump)
{
- EXPECT_EQ("S/", Stringfy::Dump(""));
- EXPECT_EQ("S/TEXT", Stringfy::Dump("TEXT"));
+ EXPECT_EQ("S/", Stringify::Dump(""));
+ EXPECT_EQ("S/TEXT", Stringify::Dump("TEXT"));
}
-TEST(StringfyTests, integer_restore)
+TEST(StringifyTests, integer_restore)
{
- auto dumped = Stringfy::Dump(-1);
- EXPECT_EQ(-1, Stringfy::Restore(dumped));
+ auto dumped = Stringify::Dump(-1);
+ EXPECT_EQ(-1, Stringify::Restore(dumped));
- dumped = Stringfy::Dump(0);
- EXPECT_EQ(0, Stringfy::Restore(dumped));
+ dumped = Stringify::Dump(0);
+ EXPECT_EQ(0, Stringify::Restore(dumped));
- dumped = Stringfy::Dump(1);
- EXPECT_EQ(1, Stringfy::Restore(dumped));
+ dumped = Stringify::Dump(1);
+ EXPECT_EQ(1, Stringify::Restore(dumped));
}
-TEST(StringfyTests, string_restore)
+TEST(StringifyTests, string_restore)
{
- auto dumped = Stringfy::Dump("");
- EXPECT_EQ(std::string(""), static_cast<std::string>(Stringfy::Restore(dumped)));
+ auto dumped = Stringify::Dump("");
+ EXPECT_EQ(std::string(""), static_cast<std::string>(Stringify::Restore(dumped)));
- dumped = Stringfy::Dump("TEXT");
- EXPECT_EQ(std::string("TEXT"), static_cast<std::string>(Stringfy::Restore(dumped)));
+ dumped = Stringify::Dump("TEXT");
+ EXPECT_EQ(std::string("TEXT"), static_cast<std::string>(Stringify::Restore(dumped)));
}
-TEST(StringfyTests, get_type)
+TEST(StringifyTests, get_type)
{
- auto dumped = Stringfy::Dump(0);
- EXPECT_EQ(Stringfy::Type::Integer, Stringfy::GetType(dumped));
+ auto dumped = Stringify::Dump(0);
+ EXPECT_EQ(Stringify::Type::Integer, Stringify::GetType(dumped));
- dumped = Stringfy::Dump("Text");
- EXPECT_EQ(Stringfy::Type::String, Stringfy::GetType(dumped));
+ dumped = Stringify::Dump("Text");
+ EXPECT_EQ(Stringify::Type::String, Stringify::GetType(dumped));
}
-TEST(StringfyTests, type_safety)
+TEST(StringifyTests, type_safety)
{
bool raised = false;
- auto dumped = Stringfy::Dump(1);
+ auto dumped = Stringify::Dump(1);
try {
- auto failed = static_cast<std::string>(Stringfy::Restore(dumped));
+ auto failed = static_cast<std::string>(Stringify::Restore(dumped));
} catch (const vist::Exception<ErrCode>& e) {
raised = true;
EXPECT_EQ(e.get(), ErrCode::TypeUnsafed);
EXPECT_TRUE(raised);
}
-TEST(StringfyTests, restore_failed)
+TEST(StringifyTests, restore_failed)
{
bool raised = false;
try {
- auto failed = Stringfy::Restore("Not dumped message");
+ auto failed = Stringify::Restore("Not dumped message");
} catch (const vist::Exception<ErrCode>& e) {
raised = true;
EXPECT_EQ(e.get(), ErrCode::LogicError);
# See the License for the specific language governing permissions and
# limitations under the License
-ADD_VIST_COMMON_LIBRARY(vist_rmi exposer.cpp
+ADD_VIST_COMMON_LIBRARY(vist_rmi gateway.cpp
remote.cpp)
FILE(GLOB RMI_TESTS "tests/*.cpp")
+++ /dev/null
-/*
- * Copyright (c) 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.
- * 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 exposer.cpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @author Jaemin Ryu (jm77.ryu@samsung.com)
- * @brief Implementation of Server-side stub for exposing method.
- */
-
-#include "exposer.hpp"
-
-#include <vist/exception.hpp>
-#include <vist/transport/message.hpp>
-#include <vist/transport/server.hpp>
-
-#include <string>
-
-namespace vist {
-namespace rmi {
-
-using namespace vist::transport;
-
-class Exposer::Impl {
-public:
- explicit Impl(Exposer& exposer, const std::string& path)
- {
- auto dispatcher = [&exposer](auto& message) -> Message {
- std::string function = message.signature;
- auto iter = exposer.functorMap.find(function);
- if (iter == exposer.functorMap.end())
- THROW(ErrCode::ProtocolBroken) << "Not found function: " << function;
-
- DEBUG(VIST) << "Remote method invokation: " << function;
-
- auto functor = iter->second;
- auto result = functor->invoke(message.buffer);
-
- Message reply(Message::Type::Reply, function);
- reply.enclose(result);
-
- return reply;
- };
-
- this->server = std::make_unique<Server>(path, dispatcher);
- }
-
- inline void start()
- {
- this->server->run();
- }
-
- inline void stop()
- {
- this->server->stop();
- }
-
-private:
- std::unique_ptr<Server> server;
-};
-
-Exposer::Exposer(const std::string& path) : pImpl(new Impl(*this, path))
-{
-}
-
-Exposer::~Exposer() = default;
-
-void Exposer::start(void)
-{
- this->pImpl->start();
-}
-
-void Exposer::stop(void)
-{
- this->pImpl->stop();
-}
-
-} // namespace rmi
-} // namespace vist
+++ /dev/null
-/*
- * Copyright (c) 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.
- * 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 exposer.hpp
- * @author Sangwan Kwon (sangwan.kwon@samsung.com)
- * @author Jaemin Ryu (jm77.ryu@samsung.com)
- * @brief Server-side stub for exposing method.
- */
-
-#pragma once
-
-#include <vist/klass/functor.hpp>
-
-#include <memory>
-#include <string>
-
-namespace vist {
-namespace rmi {
-
-class Exposer final {
-public:
- explicit Exposer(const std::string& path);
- ~Exposer();
-
- Exposer(const Exposer&) = delete;
- Exposer& operator=(const Exposer&) = delete;
-
- Exposer(Exposer&&) = default;
- Exposer& operator=(Exposer&&) = default;
-
- void start(void);
- void stop(void);
-
- template<typename O, typename F>
- void expose(O&& object, const std::string& name, F&& func);
-
-private:
- class Impl;
-
- klass::FunctorMap functorMap;
- std::unique_ptr<Impl> pImpl;
-};
-
-template<typename O, typename F>
-void Exposer::expose(O&& object, const std::string& name, F&& func)
-{
- auto functor = klass::make_functor_ptr(std::forward<O>(object), std::forward<F>(func));
- this->functorMap[name] = functor;
-}
-
-} // namespace rmi
-} // namespace vist
--- /dev/null
+/*
+ * Copyright (c) 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.
+ * 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 gateway.cpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @author Jaemin Ryu (jm77.ryu@samsung.com)
+ * @brief Implementation of Server-side stub for exposing method.
+ */
+
+#include "gateway.hpp"
+
+#include <vist/exception.hpp>
+#include <vist/transport/message.hpp>
+#include <vist/transport/server.hpp>
+
+#include <string>
+
+namespace vist {
+namespace rmi {
+
+using namespace vist::transport;
+
+class Gateway::Impl {
+public:
+ explicit Impl(Gateway& gateway, const std::string& path)
+ {
+ auto dispatcher = [&gateway](auto& message) -> Message {
+ std::string function = message.signature;
+ auto iter = gateway.functorMap.find(function);
+ if (iter == gateway.functorMap.end())
+ THROW(ErrCode::ProtocolBroken) << "Not found function: " << function;
+
+ DEBUG(VIST) << "Remote method invokation: " << function;
+
+ auto functor = iter->second;
+ auto result = functor->invoke(message.buffer);
+
+ Message reply(Message::Type::Reply, function);
+ reply.enclose(result);
+
+ return reply;
+ };
+
+ this->server = std::make_unique<Server>(path, dispatcher);
+ }
+
+ inline void start()
+ {
+ this->server->run();
+ }
+
+ inline void stop()
+ {
+ this->server->stop();
+ }
+
+private:
+ std::unique_ptr<Server> server;
+};
+
+Gateway::Gateway(const std::string& path) : pImpl(new Impl(*this, path))
+{
+}
+
+Gateway::~Gateway() = default;
+
+void Gateway::start(void)
+{
+ this->pImpl->start();
+}
+
+void Gateway::stop(void)
+{
+ this->pImpl->stop();
+}
+
+} // namespace rmi
+} // namespace vist
--- /dev/null
+/*
+ * Copyright (c) 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.
+ * 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 gateway.hpp
+ * @author Sangwan Kwon (sangwan.kwon@samsung.com)
+ * @author Jaemin Ryu (jm77.ryu@samsung.com)
+ * @brief Server-side stub for exposing method.
+ */
+
+#pragma once
+
+#include <vist/klass/functor.hpp>
+
+#include <memory>
+#include <string>
+
+namespace vist {
+namespace rmi {
+
+class Gateway final {
+public:
+ explicit Gateway(const std::string& path);
+ ~Gateway();
+
+ Gateway(const Gateway&) = delete;
+ Gateway& operator=(const Gateway&) = delete;
+
+ Gateway(Gateway&&) = default;
+ Gateway& operator=(Gateway&&) = default;
+
+ void start(void);
+ void stop(void);
+
+ template<typename O, typename F>
+ void expose(O&& object, const std::string& name, F&& func);
+
+private:
+ class Impl;
+
+ klass::FunctorMap functorMap;
+ std::unique_ptr<Impl> pImpl;
+};
+
+template<typename O, typename F>
+void Gateway::expose(O&& object, const std::string& name, F&& func)
+{
+ auto functor = klass::make_functor_ptr(std::forward<O>(object), std::forward<F>(func));
+ this->functorMap[name] = functor;
+}
+
+} // namespace rmi
+} // namespace vist
*/
-#include <vist/rmi/exposer.hpp>
+#include <vist/rmi/gateway.hpp>
#include <vist/rmi/remote.hpp>
#include <iostream>
using namespace vist::rmi;
-// exposer side methods
+// gateway side methods
struct Foo {
bool setName(const std::string& name)
{
TEST(RmiTests, positive)
{
- std::string sockPath = ("/tmp/test-exposer");
+ std::string sockPath = ("/tmp/test-gateway");
- // exposer-side
- Exposer exposer(sockPath);
+ // gateway-side
+ Gateway gateway(sockPath);
auto foo = std::make_shared<Foo>();
- exposer.expose(foo, "Foo::setName", &Foo::setName);
- exposer.expose(foo, "Foo::getName", &Foo::getName);
+ gateway.expose(foo, "Foo::setName", &Foo::setName);
+ gateway.expose(foo, "Foo::getName", &Foo::getName);
auto bar = std::make_shared<Bar>();
- exposer.expose(bar, "Bar::plusTwo", &Bar::plusTwo);
+ gateway.expose(bar, "Bar::plusTwo", &Bar::plusTwo);
auto client = std::thread([&]() {
// caller-side
int num = remote.invoke<int>("Bar::plusTwo", 3);
EXPECT_EQ(num, 5);
- exposer.stop();
+ gateway.stop();
});
- exposer.start();
+ gateway.start();
if (client.joinable())
client.join();
TEST(RmiTests, not_exist_method)
{
- std::string sockPath = ("/tmp/test-exposer");
+ std::string sockPath = ("/tmp/test-gateway");
- // exposer-side
- Exposer exposer(sockPath);
+ // gateway-side
+ Gateway gateway(sockPath);
auto client = std::thread([&]() {
// caller-side
}
EXPECT_TRUE(rasied);
- exposer.stop();
+ gateway.stop();
});
- exposer.start();
+ gateway.start();
if (client.joinable())
client.join();
struct PolicyValue final {
explicit PolicyValue() noexcept = default;
- explicit PolicyValue(int value) : stringfied(Stringfy::Dump(value)) {}
+ explicit PolicyValue(int value) : stringfied(Stringify::Dump(value)) {}
explicit PolicyValue(const std::string& value, bool dumped = false)
- : stringfied(dumped ? value : Stringfy::Dump(value)) {}
+ : stringfied(dumped ? value : Stringify::Dump(value)) {}
~PolicyValue() = default;
PolicyValue(const PolicyValue&) = default;
return this->stringfied;
}
- inline Stringfy::Type getType() const
+ inline Stringify::Type getType() const
{
- return Stringfy::GetType(this->stringfied);
+ return Stringify::GetType(this->stringfied);
}
operator int() const
{
- return Stringfy::Restore(this->stringfied);
+ return Stringify::Restore(this->stringfied);
}
operator std::string() const
{
- return Stringfy::Restore(this->stringfied);
+ return Stringify::Restore(this->stringfied);
}
private:
TEST(PolicySDKTests, policy_value_int)
{
PolicyValue value(1);
- EXPECT_EQ(Stringfy::Type::Integer, value.getType());
+ EXPECT_EQ(Stringify::Type::Integer, value.getType());
EXPECT_EQ(static_cast<int>(value), 1);
}
TEST(PolicySDKTests, policy_value_string)
{
PolicyValue value("TEXT");
- EXPECT_EQ(Stringfy::Type::String, value.getType());
+ EXPECT_EQ(Stringify::Type::String, value.getType());
EXPECT_EQ(static_cast<std::string>(value), "TEXT");
}
#include "vist.hpp"
-#include <vist/rmi/exposer.hpp>
+#include <vist/rmi/gateway.hpp>
#include <vist/logger.hpp>
#include <vist/exception.hpp>
void Vist::start()
{
INFO(VIST) << "Vist daemon starts.";
- rmi::Exposer exposer(SOCK_ADDR);
+ rmi::Gateway gateway(SOCK_ADDR);
- exposer.expose(this, "Vist::query", &Vist::query);
- exposer.start();
+ gateway.expose(this, "Vist::query", &Vist::query);
+ gateway.start();
}
Rows Vist::query(const std::string& statement)
* EXPECT_EQ(dumped, "I/1000");
*
* /// dumped string to origin type
- * int origin = Stringfy::Restore(dumped);
+ * int origin = Stringify::Restore(dumped);
* EXPECT_EQ(origin, "1000");
*/
namespace vist {
-class Stringfy final {
+class Stringify final {
public:
enum class Type : char {
Integer = 'I',
template <typename T>
static std::string Dump(T origin);
- static Stringfy Restore(const std::string& dumped);
+ static Stringify Restore(const std::string& dumped);
static Type GetType(const std::string& dumped);
operator int() const;
private:
- explicit Stringfy(int origin) noexcept;
- explicit Stringfy(const std::string& origin) noexcept;
+ explicit Stringify(int origin) noexcept;
+ explicit Stringify(const std::string& origin) noexcept;
static std::pair<Type, std::string> Parse(const std::string& dumped);
};
template <typename T>
-std::string Stringfy::Dump(T origin)
+std::string Stringify::Dump(T origin)
{
- return Stringfy(origin).dump();
+ return Stringify(origin).dump();
}
template <typename T>
-std::string Stringfy::convert(const T& origin) const noexcept
+std::string Stringify::convert(const T& origin) const noexcept
{
std::stringstream ss;
ss << static_cast<char>(this->type) << '/' << origin;