Giter Site home page Giter Site logo

message-handler's Introduction

MessageHandler

Handle your packets/messages from networking easilly.

Dependencies

  • C++ 17
  • Unordered Map C++ STD Library
  • Vector C++ STD Library
  • Functional C++ STD Library

Usage

Including library

For use this you just need to include "MessageHandler.h" file into your project.

Implementing

How each network interface is implemented on different ways, you will need to modify the code places where uses the Connection (pointer for the sender of message) & MemoryBuffer (pointer for the message buffer) classes.

Also, you will need to customize your packet handler (where messages from socket are received). This is made on Message::HandleMessage function, and you are free to let this how you want.

Example

//Instantiating Message Handler
Handler::Message messageHandler;

//Adding Global Validations (will validate every message handled from this instance)
messageHandler.AddValidation( std::bind( &GlobalValidation1, std::placeholders::_1 ) );
messageHandler.AddValidation( std::bind( &GlobalValidation2, std::placeholders::_1 ) );

//Adding Global Handling (will handle every message handled from this instance)
messageHandler.AddProcessing( std::bind( &GlobalProcessing1, std::placeholders::_1, std::placeholders::_2 ) );

//Handler for specific messages
messageHandler.Handle( 1 ).Validate( std::bind( &Message1Validation1, std::placeholders::_1 ), std::bind( &Message1Validation2, std::placeholders::_1 ) );
messageHandler.Handle( 2 ).Validate( std::bind( &Message2Validation1, std::placeholders::_1 ) );
messageHandler.Handle( 3 ).Process( std::bind( &Message3Process1, std::placeholders::_1 ) );
messageHandler.Handle( 4 );

//Testing
messageHandler.HandleMessage( 1, nullptr );
messageHandler.HandleMessage( 2, nullptr );
messageHandler.HandleMessage( 3, nullptr );
messageHandler.HandleMessage( 4, nullptr );

Message Handlers

Every handler used for some message (validation and processing), must be boolean function. When message is being handled, and at some step this has failed, everything else will be discarded. Example of validation handler:

bool GlobalValidation1( Connection* sender )
{
    if( sender )
    {
        std::cout << "Validating Message Global 1" << std::endl;
        return true;
    }

    return false;
}

Observations

Is important that you adapt the library code for your networking structure. Code files used here is just an example, and a guide for you know what to do.

Credits

message-handler's People

Contributors

igorsegallafa avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gofrettin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.