Skip to content

Commit

Permalink
Start working on attaching EchoConsole to Echo as a Service
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzcanoguz committed Nov 15, 2024
1 parent 161fcb6 commit f65605a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
14 changes: 14 additions & 0 deletions services/echo_console/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@ if (EMIL_HOST_BUILD)
Console.cpp
Console.hpp
Main.cpp
)

add_subdirectory(test)

add_library(services.console_service ${EMIL_EXCLUDE_FROM_ALL} STATIC)

target_include_directories(services.console_service PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../..>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

target_sources(services.console_service PRIVATE
ConsoleService.cpp
ConsoleService.hpp
)

add_executable(services.echo_test_tcp_server ${EMIL_EXCLUDE_FROM_ALL})
emil_install(services.echo_test_tcp_server DESTINATION bin)

Expand Down
Empty file.
68 changes: 68 additions & 0 deletions services/echo_console/ConsoleService.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef SERVICES_CONSOLE_SERVICE_HPP
#define SERVICES_CONSOLE_SERVICE_HPP

#include "infra/util/SharedOptional.hpp"
#include "protobuf/echo/Echo.hpp"
#include "services/echo_console/Console.hpp"
#include <cstdlib>

namespace services
{
class GenericMethodDeserializer
: public MethodDeserializer
{
public:
void MethodContents(infra::SharedPtr<infra::StreamReaderWithRewinding>&& reader) override
{
int a = 3;
a++;
}

void ExecuteMethod() override
{
int a = 3;
a++;
}

bool Failed() const override
{
return false;
}
};

class ConsoleServiceMethodExecute
{
public:
ConsoleServiceMethodExecute(application::Console& console)
: console(console)
{}

infra::SharedPtr<MethodDeserializer> StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const EchoErrorPolicy& errorPolicy)
{
return methodDeserializer.Emplace();
}

private:
application::Console& console;
infra::SharedOptional<GenericMethodDeserializer> methodDeserializer;
};

class ConsoleService
: public Service
{
public:
ConsoleService(Echo& echo, uint32_t serviceId, ConsoleServiceMethodExecute& methodExecute)
: Service(echo, serviceId)
, methodExecute(methodExecute)
{}

infra::SharedPtr<MethodDeserializer> StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const EchoErrorPolicy& errorPolicy) override
{
return methodExecute.StartMethod(serviceId, methodId, size, errorPolicy);
}

private:
ConsoleServiceMethodExecute& methodExecute;
};
}
#endif // CONSOLESERVICE_HPP
12 changes: 12 additions & 0 deletions services/echo_console/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_executable(services.echo_console_test)
emil_build_for(services.echo_console_test BOOL EMIL_BUILD_TESTS)
emil_add_test(services.echo_console_test)

target_sources(services.echo_console_test PRIVATE
TestConsoleService.cpp
)

target_link_libraries(services.echo_console_test PUBLIC
gmock_main
services.console_service
)
8 changes: 8 additions & 0 deletions services/echo_console/test/TestConsoleService.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "services/echo_console/ConsoleService.hpp"

class ConsoleServiceTest
: public testing::Test
{
public:

};

0 comments on commit f65605a

Please sign in to comment.