Skip to content

Commit 70a9245

Browse files
committed
Add project files.
1 parent ed652e8 commit 70a9245

File tree

12 files changed

+2048
-0
lines changed

12 files changed

+2048
-0
lines changed

FSUIPC_WAPI.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31019.35
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FSUIPC_WAPI", "FSUIPC_WAPI\FSUIPC_WAPI.vcxproj", "{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Debug|x64.ActiveCfg = Debug|x64
17+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Debug|x64.Build.0 = Debug|x64
18+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Debug|x86.ActiveCfg = Debug|Win32
19+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Debug|x86.Build.0 = Debug|Win32
20+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Release|x64.ActiveCfg = Release|x64
21+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Release|x64.Build.0 = Release|x64
22+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Release|x86.ActiveCfg = Release|Win32
23+
{EF3DC317-02E6-4ABB-8C6F-C3ECF26DAEE9}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {7CEC9B2C-E1E4-411D-9B14-B081D6F176C3}
30+
EndGlobalSection
31+
EndGlobal

FSUIPC_WAPI/CDAIdBank.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "CDAIdBank.h"
2+
#include "SimConnect.h"
3+
#include "Logger.h"
4+
5+
using namespace std;
6+
using namespace CDAIdBankMSFS;
7+
using namespace CPlusPlusLogging;
8+
9+
CDAIdBank::CDAIdBank(int id, HANDLE hSimConnect) {
10+
nextId = id;
11+
this->hSimConnect = hSimConnect;
12+
}
13+
14+
CDAIdBank::~CDAIdBank() {
15+
16+
}
17+
18+
19+
pair<string, int> CDAIdBank::getId(int size) {
20+
char szLogBuffer[512];
21+
pair<string, int> returnVal;
22+
std::map<int, pair<string, int>>::iterator it;
23+
24+
// First, check if we have one available
25+
it = availableBank.find(size);
26+
if (it != availableBank.end()) {
27+
returnVal = make_pair(it->second.first, it->second.second);
28+
availableBank.erase(it);
29+
pair<int, pair<string, int>> out = make_pair(returnVal.second, make_pair(returnVal.first, size));
30+
outBank.insert(out);
31+
}
32+
else {
33+
// Create new CDA
34+
string newName = string(CDA_NAME_TEMPLATE + to_string(nextId));
35+
returnVal = getId(size, newName);
36+
}
37+
38+
return returnVal;
39+
}
40+
41+
42+
pair<string, int> CDAIdBank::getId(int size, string name) {
43+
char szLogBuffer[512];
44+
pair<string, int> returnVal;
45+
std::map<int, pair<string, int>>::iterator it;
46+
DWORD dwLastID;
47+
48+
// First, check if we have one available
49+
it = availableBank.find(size);
50+
if (it != availableBank.end()) {
51+
returnVal = make_pair(it->second.first, it->second.second);
52+
availableBank.erase(it);
53+
pair<int, pair<string, int>> out = make_pair(returnVal.second, make_pair(returnVal.first, size));
54+
outBank.insert(out);
55+
}
56+
else {
57+
// Create new CDA
58+
string newName = string(name);
59+
returnVal = make_pair(newName, nextId);
60+
pair<int, pair<string, int>> out = make_pair(nextId, make_pair(newName, size));
61+
outBank.insert(out);
62+
63+
// Set-up CDA
64+
if (!SUCCEEDED(SimConnect_MapClientDataNameToID(hSimConnect, newName.c_str(), nextId))) {
65+
sprintf_s(szLogBuffer, sizeof(szLogBuffer), "Error mapping CDA name %s to ID %d", newName.c_str(), nextId);
66+
LOG_ERROR(szLogBuffer);
67+
}
68+
else {
69+
SimConnect_GetLastSentPacketID(hSimConnect, &dwLastID);
70+
sprintf_s(szLogBuffer, sizeof(szLogBuffer), "CDA name %s mapped to ID %d [requestId=%lu]", newName.c_str(), nextId, dwLastID);
71+
LOG_DEBUG(szLogBuffer);
72+
}
73+
74+
// Finally, Create the client data if it doesn't already exist
75+
if (!SUCCEEDED(SimConnect_CreateClientData(hSimConnect, nextId, size, SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY))) {
76+
sprintf_s(szLogBuffer, sizeof(szLogBuffer), "Error creating client data area with id=%d and size=%d", nextId, size);
77+
LOG_ERROR(szLogBuffer);
78+
}
79+
else {
80+
SimConnect_GetLastSentPacketID(hSimConnect, &dwLastID);
81+
sprintf_s(szLogBuffer, sizeof(szLogBuffer), "Client data area created with id=%d (size=%d) [requestID=%lu]", nextId, size, dwLastID);
82+
LOG_DEBUG(szLogBuffer);
83+
}
84+
nextId++;
85+
}
86+
87+
return returnVal;
88+
89+
}
90+
91+
92+
void CDAIdBank::returnId(int id) {
93+
std::map<int, pair<string, int>>::iterator it;
94+
// First, check if we have one available
95+
it = outBank.find(id);
96+
if (it != outBank.end()) {
97+
pair<string, int> p = outBank.at(id);
98+
pair<int, pair<string, int>> returnedItem = make_pair(p.second, make_pair(p.first, id));
99+
outBank.erase(it);
100+
availableBank.insert(returnedItem);
101+
}
102+
103+
}

FSUIPC_WAPI/CDAIdBank.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <windows.h>
4+
#include <string>
5+
#include <map>
6+
#include <utility>
7+
8+
#define CDA_NAME_TEMPLATE "FSUIPC_VNAME"
9+
10+
using namespace std;
11+
12+
namespace CDAIdBankMSFS {
13+
class CDAIdBank {
14+
public:
15+
CDAIdBank(int id, HANDLE hSimConnect);
16+
~CDAIdBank();
17+
pair<string, int> getId(int size);
18+
pair<string, int> getId(int size, string);
19+
void returnId(int id);
20+
21+
protected:
22+
23+
private:
24+
int nextId;
25+
multimap<int, pair<string, int>> availableBank; // keyed on size
26+
map<int, pair<string, int>> outBank; // keyed on Id
27+
HANDLE hSimConnect;
28+
};
29+
} // End of namespace

FSUIPC_WAPI/ClientDataArea.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "ClientDataArea.h"
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include <istream>
5+
#include "WASM.h"
6+
7+
using namespace std;
8+
using namespace ClientDataAreaMSFS;
9+
10+
11+
ClientDataArea::ClientDataArea(const string& cdaName, int size, CDAType type)
12+
{
13+
switch (type) {
14+
case LVAR:
15+
noItems = size / sizeof(CDAName);
16+
break;
17+
case HVAR:
18+
noItems = size / sizeof(CDAName);
19+
break;
20+
case VALUE:
21+
noItems = size / sizeof(CDAValue);
22+
break;
23+
}
24+
25+
this->id = 0;
26+
this->name = string(cdaName);
27+
this->noItems = noItems;
28+
this->size = size;
29+
this->type = type;
30+
}
31+
32+
ClientDataArea::ClientDataArea()
33+
{
34+
this->id = 0;
35+
this->size = 0;
36+
this->noItems = 0;
37+
};
38+
39+
40+
41+
int ClientDataArea::getNoItems()
42+
{
43+
return noItems;
44+
}
45+
46+
string ClientDataArea::getName()
47+
{
48+
return name;
49+
}
50+
51+
int ClientDataArea::getId()
52+
{
53+
return id;
54+
}
55+
56+
void ClientDataArea::setId(int id)
57+
{
58+
this->id = id;
59+
}
60+
61+
int ClientDataArea::getDefinitionId()
62+
{
63+
return this->definitionId;
64+
}
65+
66+
int ClientDataArea::getSize()
67+
{
68+
return size;
69+
}
70+
71+
CDAType ClientDataArea::getType()
72+
{
73+
return type;
74+
}
75+
76+
void ClientDataArea::setDefinitionId(int id)
77+
{
78+
definitionId = id;
79+
}

FSUIPC_WAPI/ClientDataArea.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
3+
#include <windows.h>
4+
#include <string>
5+
#include "WASM.h"
6+
#include "Logger.h"
7+
8+
using namespace std;
9+
using namespace CPlusPlusLogging;
10+
11+
namespace ClientDataAreaMSFS
12+
{
13+
class ClientDataArea
14+
{
15+
public:
16+
int getNoItems();
17+
void setDefinitionId(int id);
18+
int getDefinitionId();
19+
ClientDataArea(const string& cdaName, int size, CDAType type);
20+
ClientDataArea();
21+
string getName();
22+
int getSize();
23+
CDAType getType();
24+
int getId();
25+
void setId(int id);
26+
27+
protected:
28+
29+
private:
30+
string name;
31+
int id;
32+
int size;
33+
int noItems;
34+
int definitionId;
35+
CDAType type;
36+
};
37+
} // End of namespace

0 commit comments

Comments
 (0)