ADD: adden more functionality includeing a tcp server for external comms

This commit is contained in:
Henry Winkel
2023-08-16 17:06:37 +02:00
parent 115be453ac
commit 79f9c044e7
15 changed files with 1907 additions and 68 deletions

View File

@@ -0,0 +1,64 @@
#pragma once
#include "nlohmann/json_fwd.hpp"
#include <cstddef>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
namespace SimControl
{
struct PodListItem
{
std::string Uuid;
std::string Image;
std::string Ip;
std::string Component;
std::string Status;
std::string PartOf;
std::vector<std::pair<std::string,std::shared_ptr<PodListItem>>> relatedPods;
bool operator==(PodListItem const &rhs )
{
if (Uuid == rhs.Uuid) {
return true;
}
return false;
}
};
class PodList
{
public:
PodList();
PodList(std::string jsonstring);
void addPodToList(std::shared_ptr<PodListItem> pod);
void addPodToList(std::string respond);
std::shared_ptr<PodListItem> getPod(std::string uuid);
bool removePod(std::string uuid);
std::vector<std::string> getPodsUUID();
nlohmann::json getPodTree(std::string uuid);
size_t size();
private:
void addPodsFromString(std::string respond);
std::map<std::string, std::shared_ptr<PodListItem>> podList_;
};
}

View File

@@ -2,6 +2,7 @@
#define __SIMCONTROL__
#include "DirectCommunicationClient.hpp"
#include "DirectCommunicationServer.hpp"
#include "SimCore/Identifier.hpp"
#include "crossguid/guid.hpp"
#include "kubecontrol/PodController.hpp"
@@ -26,24 +27,33 @@ namespace SimControl {
class SimControl{
public:
SimControl(ushort CommandPort);
SimControl(std::string CommandPort);
~SimControl();
void stop();
private:
const SimCore::Identifier ID_;
ushort CommandPort_;
std::string CommandPort_;
void MainFunction_();
void HandleMessage(std::string msg);
void HandleExternalMessage(std::string msg);
void startShip(std::string name);
std::unique_ptr<kubecontrol::PodController> PodController_;
std::thread MainThread_;
std::atomic<bool> stopMainThread_ = false;
std::unique_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_;
std::shared_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_ = nullptr;
std::shared_ptr<DirectCommunication::DirectCommunicationServer> ExternalTCPServer_ = nullptr;