Addressed issues found by Google code lint.
Fixed: - Removed trailing whitespace. - Removed out of date TODO's. - Added #include<algorithm> to DataManager.cpp - Reordered includes to include C system headers before C++ system headers. - Added username to TODO's - Renamed include guards to use full project name as prefix. - Made methods and parameters const where possible. - Made UDPSocket constructor explicit. Won't Fix: - snprintf is introduced in C++11. - Trailing comments at the end of namespace & header guards - Did not re-inlude headers already included by the matching XPC header. - localtime is fine since X-Plane is not multithreaded at all on the plugin side. - Linter confuses #elif with parens as a function call. - namespace indentation
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "XPLMDataAccess.h"
|
#include "XPLMDataAccess.h"
|
||||||
#include "XPLMGraphics.h"
|
#include "XPLMGraphics.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -516,7 +517,7 @@ namespace XPC
|
|||||||
drefSize = min(drefSize, size);
|
drefSize = min(drefSize, size);
|
||||||
XPLMSetDatavf(xdref, values, 0, drefSize);
|
XPLMSetDatavf(xdref, values, 0, drefSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::Set(DREF dref, int values[], int size, char aircraft)
|
void DataManager::Set(DREF dref, int values[], int size, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
@@ -738,7 +739,6 @@ namespace XPC
|
|||||||
Set(DREF_LocalY, local[1], aircraft);
|
Set(DREF_LocalY, local[1], aircraft);
|
||||||
Set(DREF_LocalZ, local[2], aircraft);
|
Set(DREF_LocalZ, local[2], aircraft);
|
||||||
// If the sim is unpaused, this will override the above settings.
|
// If the sim is unpaused, this will override the above settings.
|
||||||
// TODO: Are these setable when paused? Are these necessary?
|
|
||||||
Set(DREF_Latitude, (double)pos[0], aircraft);
|
Set(DREF_Latitude, (double)pos[0], aircraft);
|
||||||
Set(DREF_Longitude, (double)pos[1], aircraft);
|
Set(DREF_Longitude, (double)pos[1], aircraft);
|
||||||
Set(DREF_Elevation, (double)pos[2], aircraft);
|
Set(DREF_Elevation, (double)pos[2], aircraft);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
||||||
//National Aeronautics and Space Administration. All Rights Reserved.
|
//National Aeronautics and Space Administration. All Rights Reserved.
|
||||||
#ifndef XPC_DATAMANAGER_H
|
#ifndef XPCPLUGIN_DATAMANAGER_H_
|
||||||
#define XPC_DATAMANAGER_H
|
#define XPCPLUGIN_DATAMANAGER_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
||||||
//National Aeronautics and Space Administration. All Rights Reserved.
|
//National Aeronautics and Space Administration. All Rights Reserved.
|
||||||
#ifndef XPC_DRAWING_H
|
#ifndef XPCPLUGIN_DRAWING_H_
|
||||||
#define XPC_DRAWING_H
|
#define XPCPLUGIN_DRAWING_H_
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
#include "XPLMUtilities.h"
|
#include "XPLMUtilities.h"
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ namespace XPC
|
|||||||
<< std::setw(2) << tm->tm_min << ":"
|
<< std::setw(2) << tm->tm_min << ":"
|
||||||
<< std::setw(2) << tm->tm_sec << "."
|
<< std::setw(2) << tm->tm_sec << "."
|
||||||
<< std::setw(3) << ms.count() << "]";
|
<< std::setw(3) << ms.count() << "]";
|
||||||
|
|
||||||
std::fprintf(fd, ss.str().c_str());
|
std::fprintf(fd, ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
||||||
//National Aeronautics and Space Administration. All Rights Reserved.
|
//National Aeronautics and Space Administration. All Rights Reserved.
|
||||||
#ifndef XPC_LOG_H
|
#ifndef XPCPLUGIN_LOG_H_
|
||||||
#define XPC_LOG_H
|
#define XPCPLUGIN_LOG_H_
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// LOG_VERBOSITY determines the level of logging throughout the plugin.
|
// LOG_VERBOSITY determines the level of logging throughout the plugin.
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ namespace XPC
|
|||||||
{
|
{
|
||||||
Message::Message() {}
|
Message::Message() {}
|
||||||
|
|
||||||
Message Message::ReadFrom(UDPSocket& sock)
|
Message Message::ReadFrom(const UDPSocket& sock)
|
||||||
{
|
{
|
||||||
Message m;
|
Message m;
|
||||||
int len = sock.Read(m.buffer, bufferSize, &m.source);
|
int len = sock.Read(m.buffer, bufferSize, &m.source);
|
||||||
m.size = len < 0 ? 0 : len;
|
m.size = len < 0 ? 0 : len;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long Message::GetMagicNumber()
|
unsigned long Message::GetMagicNumber() const
|
||||||
{
|
{
|
||||||
if (size < 4)
|
if (size < 4)
|
||||||
{
|
{
|
||||||
@@ -28,7 +28,7 @@ namespace XPC
|
|||||||
return *((unsigned long*)buffer);
|
return *((unsigned long*)buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Message::GetHead()
|
std::string Message::GetHead() const
|
||||||
{
|
{
|
||||||
if (size < 4)
|
if (size < 4)
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ namespace XPC
|
|||||||
return std::string((char*)buffer, 4);
|
return std::string((char*)buffer, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* Message::GetBuffer()
|
const unsigned char* Message::GetBuffer() const
|
||||||
{
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
@@ -46,17 +46,17 @@ namespace XPC
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t Message::GetSize()
|
std::size_t Message::GetSize() const
|
||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr Message::GetSource()
|
struct sockaddr Message::GetSource() const
|
||||||
{
|
{
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Message::PrintToLog()
|
void Message::PrintToLog() const
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
||||||
//National Aeronautics and Space Administration. All Rights Reserved.
|
//National Aeronautics and Space Administration. All Rights Reserved.
|
||||||
#ifndef XPC_MESSAGE_H
|
#ifndef XPCPLUGIN_MESSAGE_H_
|
||||||
#define XPC_MESSAGE_H
|
#define XPCPLUGIN_MESSAGE_H_
|
||||||
|
|
||||||
#include "UDPSocket.h"
|
#include "UDPSocket.h"
|
||||||
|
|
||||||
@@ -24,25 +24,25 @@ namespace XPC
|
|||||||
/// \returns A message parsed from the data read from sock. If no
|
/// \returns A message parsed from the data read from sock. If no
|
||||||
/// data was read or an error occurs, returns a message
|
/// data was read or an error occurs, returns a message
|
||||||
/// with the size set to 0.
|
/// with the size set to 0.
|
||||||
static Message ReadFrom(UDPSocket& sock);
|
static Message ReadFrom(const UDPSocket& sock);
|
||||||
|
|
||||||
/// Gets the message header in binary form.
|
/// Gets the message header in binary form.
|
||||||
unsigned long GetMagicNumber();
|
unsigned long GetMagicNumber() const;
|
||||||
|
|
||||||
/// Gets the message header.
|
/// Gets the message header.
|
||||||
std::string GetHead();
|
std::string GetHead() const;
|
||||||
|
|
||||||
/// Gets the buffer underlying the message.
|
/// Gets the buffer underlying the message.
|
||||||
const unsigned char* GetBuffer();
|
const unsigned char* GetBuffer() const;
|
||||||
|
|
||||||
/// Gets the size of the message in bytes.
|
/// Gets the size of the message in bytes.
|
||||||
std::size_t GetSize();
|
std::size_t GetSize() const;
|
||||||
|
|
||||||
/// Gets the address this message was read from.
|
/// Gets the address this message was read from.
|
||||||
struct sockaddr GetSource();
|
struct sockaddr GetSource() const;
|
||||||
|
|
||||||
/// Prints the contents of the message to the XPC log.
|
/// Prints the contents of the message to the XPC log.
|
||||||
void PrintToLog();
|
void PrintToLog() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Message();
|
Message();
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ namespace XPC
|
|||||||
connection.id, connectionKey.c_str());
|
connection.id, connectionKey.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there is a handler for this message type. If so, execute
|
// Check if there is a handler for this message type. If so, execute
|
||||||
// that handler. Otherwise, execute the unknown message handler.
|
// that handler. Otherwise, execute the unknown message handler.
|
||||||
std::map<std::string, MessageHandler>::iterator iter = handlers.find(head);
|
std::map<std::string, MessageHandler>::iterator iter = handlers.find(head);
|
||||||
@@ -128,7 +128,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleConn(Message& msg)
|
void MessageHandlers::HandleConn(const Message& msg)
|
||||||
{
|
{
|
||||||
const unsigned char* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ namespace XPC
|
|||||||
sock->SendTo(response, 6, &connection.addr);
|
sock->SendTo(response, 6, &connection.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleCtrl(Message& msg)
|
void MessageHandlers::HandleCtrl(const Message& msg)
|
||||||
{
|
{
|
||||||
// Update Log
|
// Update Log
|
||||||
#if LOG_VERBOSITY > 2
|
#if LOG_VERBOSITY > 2
|
||||||
@@ -252,7 +252,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleData(Message& msg)
|
void MessageHandlers::HandleData(const Message& msg)
|
||||||
{
|
{
|
||||||
// Parse data
|
// Parse data
|
||||||
const unsigned char* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
@@ -402,7 +402,7 @@ namespace XPC
|
|||||||
DREF dref = XPData[dataRef][j];
|
DREF dref = XPData[dataRef][j];
|
||||||
if (dref == DREF_None)
|
if (dref == DREF_None)
|
||||||
{
|
{
|
||||||
// TODO: Send single line instead!
|
// TODO(jason): Send single line instead!
|
||||||
HandleXPlaneData(msg);
|
HandleXPlaneData(msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -415,7 +415,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleDref(Message& msg)
|
void MessageHandlers::HandleDref(const Message& msg)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY >= 3
|
#if LOG_VERBOSITY >= 3
|
||||||
Log::FormatLine("[DREF] Request to set DREF value received (Conn %i)", connection.id);
|
Log::FormatLine("[DREF] Request to set DREF value received (Conn %i)", connection.id);
|
||||||
@@ -454,7 +454,7 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleGetD(Message& msg)
|
void MessageHandlers::HandleGetD(const Message& msg)
|
||||||
{
|
{
|
||||||
const unsigned char* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
unsigned char drefCount = buffer[5];
|
unsigned char drefCount = buffer[5];
|
||||||
@@ -504,7 +504,7 @@ namespace XPC
|
|||||||
sock->SendTo(response, cur, &connection.addr);
|
sock->SendTo(response, cur, &connection.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandlePosi(Message& msg)
|
void MessageHandlers::HandlePosi(const Message& msg)
|
||||||
{
|
{
|
||||||
// Update log
|
// Update log
|
||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
@@ -548,7 +548,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleSimu(Message& msg)
|
void MessageHandlers::HandleSimu(const Message& msg)
|
||||||
{
|
{
|
||||||
// Update log
|
// Update log
|
||||||
#if LOG_VERBOSITY > 1
|
#if LOG_VERBOSITY > 1
|
||||||
@@ -600,7 +600,7 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleText(Message& msg)
|
void MessageHandlers::HandleText(const Message& msg)
|
||||||
{
|
{
|
||||||
// Update Log
|
// Update Log
|
||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
@@ -638,7 +638,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleView(Message& msg)
|
void MessageHandlers::HandleView(const Message& msg)
|
||||||
{
|
{
|
||||||
// Update Log
|
// Update Log
|
||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
@@ -658,7 +658,7 @@ namespace XPC
|
|||||||
XPLMCommandKeyStroke(type);
|
XPLMCommandKeyStroke(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleWypt(Message& msg)
|
void MessageHandlers::HandleWypt(const Message& msg)
|
||||||
{
|
{
|
||||||
// Update Log
|
// Update Log
|
||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
@@ -702,7 +702,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleXPlaneData(Message& msg)
|
void MessageHandlers::HandleXPlaneData(const Message& msg)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 1
|
#if LOG_VERBOSITY > 1
|
||||||
Log::WriteLine("[MSGH] Sending raw data to X-Plane");
|
Log::WriteLine("[MSGH] Sending raw data to X-Plane");
|
||||||
@@ -714,7 +714,7 @@ namespace XPC
|
|||||||
sock->SendTo(msg.GetBuffer(), msg.GetSize(), (sockaddr*)&loopback);
|
sock->SendTo(msg.GetBuffer(), msg.GetSize(), (sockaddr*)&loopback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleUnknown(Message& msg)
|
void MessageHandlers::HandleUnknown(const Message& msg)
|
||||||
{
|
{
|
||||||
// UPDATE LOG
|
// UPDATE LOG
|
||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
||||||
//National Aeronautics and Space Administration. All Rights Reserved.
|
//National Aeronautics and Space Administration. All Rights Reserved.
|
||||||
#ifndef XPC_MESSAGEHANDLERS_H
|
#ifndef XPCPLUGIN_MESSAGEHANDLERS_H_
|
||||||
#define XPC_MESSAGEHANDLERS_H
|
#define XPCPLUGIN_MESSAGEHANDLERS_H_
|
||||||
#include "Message.h"
|
#include "Message.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
namespace XPC
|
namespace XPC
|
||||||
{
|
{
|
||||||
/// A function that handles a message.
|
/// A function that handles a message.
|
||||||
typedef void(*MessageHandler)(Message&);
|
typedef void(*MessageHandler)(const Message&);
|
||||||
|
|
||||||
/// Handles incommming messages and manages connections.
|
/// Handles incommming messages and manages connections.
|
||||||
///
|
///
|
||||||
@@ -37,18 +37,18 @@ namespace XPC
|
|||||||
static void SetSocket(UDPSocket* socket);
|
static void SetSocket(UDPSocket* socket);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void HandleConn(Message& msg);
|
static void HandleConn(const Message& msg);
|
||||||
static void HandleCtrl(Message& msg);
|
static void HandleCtrl(const Message& msg);
|
||||||
static void HandleData(Message& msg);
|
static void HandleData(const Message& msg);
|
||||||
static void HandleDref(Message& msg);
|
static void HandleDref(const Message& msg);
|
||||||
static void HandleGetD(Message& msg);
|
static void HandleGetD(const Message& msg);
|
||||||
static void HandlePosi(Message& msg);
|
static void HandlePosi(const Message& msg);
|
||||||
static void HandleSimu(Message& msg);
|
static void HandleSimu(const Message& msg);
|
||||||
static void HandleText(Message& msg);
|
static void HandleText(const Message& msg);
|
||||||
static void HandleWypt(Message& msg);
|
static void HandleWypt(const Message& msg);
|
||||||
static void HandleView(Message& msg);
|
static void HandleView(const Message& msg);
|
||||||
static void HandleXPlaneData(Message& msg);
|
static void HandleXPlaneData(const Message& msg);
|
||||||
static void HandleUnknown(Message& msg);
|
static void HandleUnknown(const Message& msg);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace XPC
|
|||||||
localAddr.sin_family = AF_INET;
|
localAddr.sin_family = AF_INET;
|
||||||
localAddr.sin_addr.s_addr = INADDR_ANY;
|
localAddr.sin_addr.s_addr = INADDR_ANY;
|
||||||
localAddr.sin_port = htons(recvPort);
|
localAddr.sin_port = htons(recvPort);
|
||||||
|
|
||||||
//Create and bind the socket
|
//Create and bind the socket
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsa;
|
WSADATA wsa;
|
||||||
@@ -92,7 +92,7 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPSocket::Read(unsigned char* dst, int maxLen, sockaddr* recvAddr)
|
int UDPSocket::Read(unsigned char* dst, int maxLen, sockaddr* recvAddr) const
|
||||||
{
|
{
|
||||||
socklen_t recvaddrlen = sizeof(*recvAddr);
|
socklen_t recvaddrlen = sizeof(*recvAddr);
|
||||||
int status = 0;
|
int status = 0;
|
||||||
@@ -137,7 +137,7 @@ namespace XPC
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPSocket::SendTo(const unsigned char* buffer, std::size_t len, sockaddr* remote)
|
void UDPSocket::SendTo(const unsigned char* buffer, std::size_t len, sockaddr* remote) const
|
||||||
{
|
{
|
||||||
if (sendto(sock, (char*)buffer, (int)len, 0, remote, sizeof(*remote)) < 0)
|
if (sendto(sock, (char*)buffer, (int)len, 0, remote, sizeof(*remote)) < 0)
|
||||||
{
|
{
|
||||||
@@ -152,7 +152,7 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UDPSocket::GetHost(sockaddr* sa)
|
std::string UDPSocket::GetHost(sockaddr* sa)
|
||||||
{
|
{
|
||||||
char ip[INET6_ADDRSTRLEN + 6] = { 0 };
|
char ip[INET6_ADDRSTRLEN + 6] = { 0 };
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
|
||||||
//National Aeronautics and Space Administration. All Rights Reserved.
|
//National Aeronautics and Space Administration. All Rights Reserved.
|
||||||
#ifndef XPC_SOCKET_H
|
#ifndef XPCPLUGIN_SOCKET_H_
|
||||||
#define XPC_SOCKET_H
|
#define XPCPLUGIN_SOCKET_H_
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#pragma comment(lib,"ws2_32.lib") //Winsock Library
|
#pragma comment(lib, "ws2_32.lib") //Winsock Library
|
||||||
#elif (__APPLE__ || __linux)
|
#elif (__APPLE__ || __linux)
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -34,7 +34,7 @@ namespace XPC
|
|||||||
/// specified receive port.
|
/// specified receive port.
|
||||||
///
|
///
|
||||||
/// \param recvPort The port on which this instance will receive data.
|
/// \param recvPort The port on which this instance will receive data.
|
||||||
UDPSocket(unsigned short recvPort);
|
explicit UDPSocket(unsigned short recvPort);
|
||||||
|
|
||||||
/// Closes the underlying socket for this instance.
|
/// Closes the underlying socket for this instance.
|
||||||
~UDPSocket();
|
~UDPSocket();
|
||||||
@@ -48,14 +48,14 @@ namespace XPC
|
|||||||
/// of the remote host.
|
/// of the remote host.
|
||||||
/// \returns The number of bytes read, or a negative number if
|
/// \returns The number of bytes read, or a negative number if
|
||||||
/// an error occurs.
|
/// an error occurs.
|
||||||
int Read(unsigned char* buffer, int size, sockaddr* remoteAddr);
|
int Read(unsigned char* buffer, int size, sockaddr* remoteAddr) const;
|
||||||
|
|
||||||
/// Sends data to the specified remote endpoint.
|
/// Sends data to the specified remote endpoint.
|
||||||
///
|
///
|
||||||
/// \param data The data to be sent.
|
/// \param data The data to be sent.
|
||||||
/// \param len The number of bytes to send.
|
/// \param len The number of bytes to send.
|
||||||
/// \param remote The destination socket.
|
/// \param remote The destination socket.
|
||||||
void SendTo(const unsigned char* buffer, std::size_t len, sockaddr* remote);
|
void SendTo(const unsigned char* buffer, std::size_t len, sockaddr* remote) const;
|
||||||
|
|
||||||
/// Gets a string containing the IP address and port contained in the given sockaddr.
|
/// Gets a string containing the IP address and port contained in the given sockaddr.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//National Aeronautics and Space Administration. All Rights Reserved.
|
//National Aeronautics and Space Administration. All Rights Reserved.
|
||||||
//
|
//
|
||||||
//DISCLAIMERS
|
//DISCLAIMERS
|
||||||
// No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND,
|
// No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND,
|
||||||
// EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT
|
// EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT
|
||||||
// THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
|
// THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY
|
||||||
@@ -75,7 +75,8 @@
|
|||||||
|
|
||||||
XPC::UDPSocket* sock = NULL;
|
XPC::UDPSocket* sock = NULL;
|
||||||
|
|
||||||
double start,lap;
|
double start;
|
||||||
|
double lap;
|
||||||
static double timeConvert = 0.0;
|
static double timeConvert = 0.0;
|
||||||
int benchmarkingSwitch = 0; // 1 = time for operations, 2 = time for op + cycle;
|
int benchmarkingSwitch = 0; // 1 = time for operations, 2 = time for op + cycle;
|
||||||
int cyclesToClear = -1; // Clear message bus every n cycles. -1 == dont clear
|
int cyclesToClear = -1; // Clear message bus every n cycles. -1 == dont clear
|
||||||
@@ -93,12 +94,12 @@ PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc)
|
|||||||
strcpy(outName, "X-Plane Connect [Version 1.0.1]");
|
strcpy(outName, "X-Plane Connect [Version 1.0.1]");
|
||||||
strcpy(outSig, "NASA.XPlaneConnect");
|
strcpy(outSig, "NASA.XPlaneConnect");
|
||||||
strcpy(outDesc, "X Plane Communications Toolbox\nCopyright (c) 2013-2015 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.");
|
strcpy(outDesc, "X Plane Communications Toolbox\nCopyright (c) 2013-2015 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.");
|
||||||
|
|
||||||
#if (__APPLE__)
|
#if (__APPLE__)
|
||||||
if ( abs(timeConvert) <= 1e-9 ) // is about 0
|
if ( abs(timeConvert) <= 1e-9 ) // is about 0
|
||||||
{
|
{
|
||||||
mach_timebase_info_data_t timeBase;
|
mach_timebase_info_data_t timeBase;
|
||||||
(void)mach_timebase_info( &timeBase );
|
(void)mach_timebase_info(&timeBase);
|
||||||
timeConvert = (double)timeBase.numer /
|
timeConvert = (double)timeBase.numer /
|
||||||
(double)timeBase.denom /
|
(double)timeBase.denom /
|
||||||
1000000000.0;
|
1000000000.0;
|
||||||
@@ -107,11 +108,11 @@ PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc)
|
|||||||
XPC::Log::Initialize("1.0.1");
|
XPC::Log::Initialize("1.0.1");
|
||||||
XPC::Log::WriteLine("[EXEC] Plugin Start");
|
XPC::Log::WriteLine("[EXEC] Plugin Start");
|
||||||
XPC::DataManager::Initialize();
|
XPC::DataManager::Initialize();
|
||||||
|
|
||||||
float interval = -1; // Call every frame
|
float interval = -1; // Call every frame
|
||||||
void* refcon = NULL; // Don't pass anything to the callback directly
|
void* refcon = NULL; // Don't pass anything to the callback directly
|
||||||
XPLMRegisterFlightLoopCallback(XPCFlightLoopCallback, interval, refcon);
|
XPLMRegisterFlightLoopCallback(XPCFlightLoopCallback, interval, refcon);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +152,7 @@ PLUGIN_API int XPluginEnable(void)
|
|||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
XPC::Log::FormatLine("[EXEC] Debug Logging Enabled (Verbosity: %i)", LOG_VERBOSITY);
|
XPC::Log::FormatLine("[EXEC] Debug Logging Enabled (Verbosity: %i)", LOG_VERBOSITY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,8 +197,8 @@ float XPCFlightLoopCallback(float inElapsedSinceLastCall,
|
|||||||
{
|
{
|
||||||
#if (__APPLE__)
|
#if (__APPLE__)
|
||||||
lap = (double)mach_absolute_time( ) * timeConvert;
|
lap = (double)mach_absolute_time( ) * timeConvert;
|
||||||
diff_t = lap-start;
|
diff_t = lap - start;
|
||||||
XPC::Log::FormatLine("[BENCH] Runtime %.6f",diff_t);
|
XPC::Log::FormatLine("[BENCH] Runtime %.6f", diff_t);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user