// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include using namespace mbus; class Server : public IMessageHandler { private: DestinationSession::UP _session; public: Server(MessageBus &bus); ~Server(); void handleMessage(Message::UP msg) override; }; Server::Server(MessageBus &bus) : _session(bus.createDestinationSession("session", true, *this)) { fprintf(stderr, "cpp server started\n"); } Server::~Server() { _session.reset(); } void Server::handleMessage(Message::UP msg) { Reply::UP reply(new EmptyReply()); msg->swapState(*reply); reply->addError(Error(ErrorCode::APP_FATAL_ERROR + 1, "ERR 1")); reply->addError(Error(ErrorCode::APP_FATAL_ERROR + 2, "ERR 2")); _session->reply(std::move(reply)); } class App : public FastOS_Application { public: int Main() override; }; int App::Main() { RPCMessageBus mb(ProtocolSet().add(std::make_shared()), RPCNetworkParams("file:slobrok.cfg") .setIdentity(Identity("server/cpp")), "file:routing.cfg"); Server server(mb.getMessageBus()); while (true) { FastOS_Thread::Sleep(1000); } return 0; } int main(int argc, char **argv) { App app; return app.Entry(argc, argv); }