GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cc_tutorial/tutorials/tutorial11/src/ClientSession.h at master · commschamp/cc_tutorial Expand file tree/ Copy pathClientSession.hMore file actions 105 lines (84 loc) · 3.04 KB / Copy pathClientSession.hFile metadata and controls105 lines (84 loc) · 3.04 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 #pragma once #include <iterator> #include <vector> #include "tutorial11/Message.h" #include "tutorial11/frame/Frame.h" #include "tutorial11/input/ClientInputMessages.h" #include "tutorial11/options/ClientDefaultOptions.h" #include "Session.h" #include "ProtocolOptions.h" namespace cc_tutorial { class ClientSession : public Session { using Base = Session; public: using Base::Base; // Inherit constructors // Common interface class for all the messages using Message = tutorial11::Message<>; // Protocol options for client using ClientProtocolOptions = ProtocolOptionsT< tutorial11::options::ClientDefaultOptions >; // Definition of all the used message classes using Msg1 = tutorial11::message::Msg1<Message, ClientProtocolOptions>; using Msg2 = tutorial11::message::Msg2<Message, ClientProtocolOptions>; using Msg3 = tutorial11::message::Msg3<Message, ClientProtocolOptions>; // Handling functions for all the dispatched message objects template <typename TMsg> void handle(TMsg& msg) { std::cout << "Received \"" << msg.doName() << "\" with ID=" << (unsigned)msg.doGetId() << '\n'; doNextStage(); } void handle(Message& msg); protected: virtual bool startImpl() override final; virtual std::size_t processInputImpl(const std::uint8_t* buf, std::size_t bufLen) override final; private: enum CommsStage { CommsStage_Msg1, CommsStage_Msg2, CommsStage_Msg3, CommsStage_NumOfValues }; // Send the message requires knowledge about the full message type template <typename TMsg> void sendMessage(const TMsg& msg) { std::cout << "Sending message \"" << msg.doName() << "\" with ID=" << (unsigned)msg.doGetId() << std::endl; // The statement below uses polymorphic message name and ID retrievals. std::vector<std::uint8_t> output; // Use polymorphic serialization length calculation to reserve // needed capacity output.reserve(m_frame.length(msg)); // Serialize message into the buffer (including framing) // The serialization uses polymorphic write functionality. auto writeIter = std::back_inserter(output); // The frame will use polymorphic message ID retrieval to // prefix message payload with message ID auto es = m_frame.write(msg, writeIter, output.max_size()); if (es != comms::ErrorStatus::Success) { assert(!"Write operation failed unexpectedly"); return; } // Send serialized message back sendOutput(&output[0], output.size()); } void doNextStage(); void sendMsg1(); void sendMsg2(); void sendMsg3(); // Client specific frame using Frame = tutorial11::frame::Frame< Message, tutorial11::input::ClientInputMessages<Message, ClientProtocolOptions>, ClientProtocolOptions >; Frame m_frame; CommsStage m_currentStage = CommsStage_NumOfValues; }; } // namespace cc_tutorial |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |