From df3366f1112939307e51a59eb902a77b0aab4efe Mon Sep 17 00:00:00 2001 From: Sangwan Kwon Date: Wed, 18 Dec 2019 18:22:31 +0900 Subject: [PATCH] Rename RMI Exposer to Gateway Also Stringfy is changed to Stringify Signed-off-by: Sangwan Kwon --- src/vist/client/virtual-table.cpp | 2 +- src/vist/common/stringfy.cpp | 28 +++++++------- src/vist/common/tests/stringfy.cpp | 62 +++++++++++++++---------------- src/vist/rmi/CMakeLists.txt | 2 +- src/vist/rmi/{exposer.cpp => gateway.cpp} | 22 +++++------ src/vist/rmi/{exposer.hpp => gateway.hpp} | 18 ++++----- src/vist/rmi/tests/rmi.cpp | 30 +++++++-------- src/vist/sdk/policy-value.hpp | 12 +++--- src/vist/sdk/tests/sdk.cpp | 4 +- src/vist/service/vist.cpp | 8 ++-- src/vist/stringfy.hpp | 16 ++++---- 11 files changed, 102 insertions(+), 102 deletions(-) rename src/vist/rmi/{exposer.cpp => gateway.cpp} (80%) rename src/vist/rmi/{exposer.hpp => gateway.hpp} (80%) diff --git a/src/vist/client/virtual-table.cpp b/src/vist/client/virtual-table.cpp index b8deacf..714e17d 100644 --- a/src/vist/client/virtual-table.cpp +++ b/src/vist/client/virtual-table.cpp @@ -100,7 +100,7 @@ Member VirtualRow::at(Member Struct::* field) const } if (std::is_same>::value && key == "value") - return static_cast(Stringfy::Restore(value)); + return static_cast(Stringify::Restore(value)); try { return boost::lexical_cast(value); diff --git a/src/vist/common/stringfy.cpp b/src/vist/common/stringfy.cpp index 7f0cce3..3dbde56 100644 --- a/src/vist/common/stringfy.cpp +++ b/src/vist/common/stringfy.cpp @@ -18,54 +18,54 @@ 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::Parse(const std::string& dumped) +std::pair Stringify::Parse(const std::string& dumped) { std::string type = dumped.substr(0, dumped.find('/')); std::string data = dumped.substr(dumped.find('/') + 1); @@ -75,7 +75,7 @@ std::pair Stringfy::Parse(const std::string& dumped return std::make_pair(static_cast(type.at(0)), data); } -std::string Stringfy::dump() const noexcept +std::string Stringify::dump() const noexcept { return this->buffer; } diff --git a/src/vist/common/tests/stringfy.cpp b/src/vist/common/tests/stringfy.cpp index 01f5e40..e5375c0 100644 --- a/src/vist/common/tests/stringfy.cpp +++ b/src/vist/common/tests/stringfy.cpp @@ -21,58 +21,58 @@ 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(Stringfy::Restore(dumped))); + auto dumped = Stringify::Dump(""); + EXPECT_EQ(std::string(""), static_cast(Stringify::Restore(dumped))); - dumped = Stringfy::Dump("TEXT"); - EXPECT_EQ(std::string("TEXT"), static_cast(Stringfy::Restore(dumped))); + dumped = Stringify::Dump("TEXT"); + EXPECT_EQ(std::string("TEXT"), static_cast(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(Stringfy::Restore(dumped)); + auto failed = static_cast(Stringify::Restore(dumped)); } catch (const vist::Exception& e) { raised = true; EXPECT_EQ(e.get(), ErrCode::TypeUnsafed); @@ -81,12 +81,12 @@ TEST(StringfyTests, type_safety) 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& e) { raised = true; EXPECT_EQ(e.get(), ErrCode::LogicError); diff --git a/src/vist/rmi/CMakeLists.txt b/src/vist/rmi/CMakeLists.txt index 9f439e0..01b8e67 100644 --- a/src/vist/rmi/CMakeLists.txt +++ b/src/vist/rmi/CMakeLists.txt @@ -12,7 +12,7 @@ # 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") diff --git a/src/vist/rmi/exposer.cpp b/src/vist/rmi/gateway.cpp similarity index 80% rename from src/vist/rmi/exposer.cpp rename to src/vist/rmi/gateway.cpp index 3c2a66b..02b2f06 100644 --- a/src/vist/rmi/exposer.cpp +++ b/src/vist/rmi/gateway.cpp @@ -14,13 +14,13 @@ * limitations under the License */ /* - * @file exposer.cpp + * @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 "exposer.hpp" +#include "gateway.hpp" #include #include @@ -33,14 +33,14 @@ namespace rmi { using namespace vist::transport; -class Exposer::Impl { +class Gateway::Impl { public: - explicit Impl(Exposer& exposer, const std::string& path) + explicit Impl(Gateway& gateway, const std::string& path) { - auto dispatcher = [&exposer](auto& message) -> Message { + auto dispatcher = [&gateway](auto& message) -> Message { std::string function = message.signature; - auto iter = exposer.functorMap.find(function); - if (iter == exposer.functorMap.end()) + auto iter = gateway.functorMap.find(function); + if (iter == gateway.functorMap.end()) THROW(ErrCode::ProtocolBroken) << "Not found function: " << function; DEBUG(VIST) << "Remote method invokation: " << function; @@ -71,18 +71,18 @@ private: std::unique_ptr server; }; -Exposer::Exposer(const std::string& path) : pImpl(new Impl(*this, path)) +Gateway::Gateway(const std::string& path) : pImpl(new Impl(*this, path)) { } -Exposer::~Exposer() = default; +Gateway::~Gateway() = default; -void Exposer::start(void) +void Gateway::start(void) { this->pImpl->start(); } -void Exposer::stop(void) +void Gateway::stop(void) { this->pImpl->stop(); } diff --git a/src/vist/rmi/exposer.hpp b/src/vist/rmi/gateway.hpp similarity index 80% rename from src/vist/rmi/exposer.hpp rename to src/vist/rmi/gateway.hpp index e4c2a99..b8a347b 100644 --- a/src/vist/rmi/exposer.hpp +++ b/src/vist/rmi/gateway.hpp @@ -14,7 +14,7 @@ * limitations under the License */ /* - * @file exposer.hpp + * @file gateway.hpp * @author Sangwan Kwon (sangwan.kwon@samsung.com) * @author Jaemin Ryu (jm77.ryu@samsung.com) * @brief Server-side stub for exposing method. @@ -30,16 +30,16 @@ namespace vist { namespace rmi { -class Exposer final { +class Gateway final { public: - explicit Exposer(const std::string& path); - ~Exposer(); + explicit Gateway(const std::string& path); + ~Gateway(); - Exposer(const Exposer&) = delete; - Exposer& operator=(const Exposer&) = delete; + Gateway(const Gateway&) = delete; + Gateway& operator=(const Gateway&) = delete; - Exposer(Exposer&&) = default; - Exposer& operator=(Exposer&&) = default; + Gateway(Gateway&&) = default; + Gateway& operator=(Gateway&&) = default; void start(void); void stop(void); @@ -55,7 +55,7 @@ private: }; template -void Exposer::expose(O&& object, const std::string& name, F&& func) +void Gateway::expose(O&& object, const std::string& name, F&& func) { auto functor = klass::make_functor_ptr(std::forward(object), std::forward(func)); this->functorMap[name] = functor; diff --git a/src/vist/rmi/tests/rmi.cpp b/src/vist/rmi/tests/rmi.cpp index 08eb727..250bed5 100644 --- a/src/vist/rmi/tests/rmi.cpp +++ b/src/vist/rmi/tests/rmi.cpp @@ -20,7 +20,7 @@ */ -#include +#include #include #include @@ -32,7 +32,7 @@ using namespace vist::rmi; -// exposer side methods +// gateway side methods struct Foo { bool setName(const std::string& name) { @@ -57,17 +57,17 @@ struct Bar { 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(); - 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(); - exposer.expose(bar, "Bar::plusTwo", &Bar::plusTwo); + gateway.expose(bar, "Bar::plusTwo", &Bar::plusTwo); auto client = std::thread([&]() { // caller-side @@ -83,10 +83,10 @@ TEST(RmiTests, positive) int num = remote.invoke("Bar::plusTwo", 3); EXPECT_EQ(num, 5); - exposer.stop(); + gateway.stop(); }); - exposer.start(); + gateway.start(); if (client.joinable()) client.join(); @@ -94,10 +94,10 @@ TEST(RmiTests, positive) 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 @@ -113,10 +113,10 @@ TEST(RmiTests, not_exist_method) } EXPECT_TRUE(rasied); - exposer.stop(); + gateway.stop(); }); - exposer.start(); + gateway.start(); if (client.joinable()) client.join(); diff --git a/src/vist/sdk/policy-value.hpp b/src/vist/sdk/policy-value.hpp index 98269a0..357c72f 100644 --- a/src/vist/sdk/policy-value.hpp +++ b/src/vist/sdk/policy-value.hpp @@ -25,9 +25,9 @@ namespace policy { 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; @@ -41,19 +41,19 @@ struct PolicyValue final { 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: diff --git a/src/vist/sdk/tests/sdk.cpp b/src/vist/sdk/tests/sdk.cpp index 9b2ceb7..1ccdd6a 100644 --- a/src/vist/sdk/tests/sdk.cpp +++ b/src/vist/sdk/tests/sdk.cpp @@ -51,14 +51,14 @@ public: 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(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(value), "TEXT"); } diff --git a/src/vist/service/vist.cpp b/src/vist/service/vist.cpp index 596c4a3..8978d04 100644 --- a/src/vist/service/vist.cpp +++ b/src/vist/service/vist.cpp @@ -16,7 +16,7 @@ #include "vist.hpp" -#include +#include #include #include @@ -37,10 +37,10 @@ Vist::Vist() 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) diff --git a/src/vist/stringfy.hpp b/src/vist/stringfy.hpp index d5b64a5..117d612 100644 --- a/src/vist/stringfy.hpp +++ b/src/vist/stringfy.hpp @@ -21,7 +21,7 @@ * EXPECT_EQ(dumped, "I/1000"); * * /// dumped string to origin type - * int origin = Stringfy::Restore(dumped); + * int origin = Stringify::Restore(dumped); * EXPECT_EQ(origin, "1000"); */ @@ -33,7 +33,7 @@ namespace vist { -class Stringfy final { +class Stringify final { public: enum class Type : char { Integer = 'I', @@ -43,7 +43,7 @@ public: template 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); @@ -51,8 +51,8 @@ public: 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 Parse(const std::string& dumped); @@ -66,13 +66,13 @@ private: }; template -std::string Stringfy::Dump(T origin) +std::string Stringify::Dump(T origin) { - return Stringfy(origin).dump(); + return Stringify(origin).dump(); } template -std::string Stringfy::convert(const T& origin) const noexcept +std::string Stringify::convert(const T& origin) const noexcept { std::stringstream ss; ss << static_cast(this->type) << '/' << origin; -- 2.7.4