Refactored message handling code into the MessageHandlers class.

- Re-enabled CONF messages sent in response to CONN commands.
 - There was a bug in the construction of the CONF message.
 - Resolves nasa/XPlaneConnect#31
This commit is contained in:
Jason Watkins
2015-04-11 16:21:00 -07:00
parent 6c51fa476e
commit 52bf998632
8 changed files with 696 additions and 729 deletions

View File

@@ -0,0 +1,53 @@
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
//National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPC_MESSAGEHANDLERS_H
#define XPC_MESSAGEHANDLERS_H
#include "Message.h"
#include "UDPSocket.h"
#include <string>
#include <unordered_map>
namespace XPC
{
typedef void(*MessageHandler)(Message&);
class MessageHandlers
{
public:
static void HandleMessage(Message& msg);
static void SetSocket(UDPSocket* socket);
private:
static void HandleConn(Message& msg);
static void HandleCtrl(Message& msg);
static void HandleData(Message& msg);
static void HandleDref(Message& msg);
static void HandleGetD(Message& msg);
static void HandlePosi(Message& msg);
static void HandleSimu(Message& msg);
static void HandleText(Message& msg);
static void HandleWypt(Message& msg);
static void HandleXPlaneData(Message& msg);
static void HandleUnknown(Message& msg);
typedef struct
{
std::uint8_t id;
std::string ip;
std::uint16_t dstPort;
std::uint16_t srcPort;
std::uint8_t getdCount;
std::string getdRequest[255];
} ConnectionInfo;
static std::unordered_map<std::string, ConnectionInfo> connections;
static std::unordered_map<std::string, MessageHandler> handlers;
static std::string connectionKey;
static ConnectionInfo connection;
static UDPSocket* sock;
};
}
#endif