Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
SFSoap.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef _SFSoap_H
7#define _SFSoap_H
8
9#include "Define.h"
11
12#include <condition_variable>
13#include <functional>
14#include <mutex>
15#include <string>
16#include <utility>
17
19{
20public:
22
23 void Run();
24
25 void SetListenArguments(const std::string& host, uint16 port)
26 {
27 _host = host;
28 _port = port;
29 }
30
31private:
32 void process_message(struct soap* soap);
33
34 std::string _host;
36};
37
39{
40public:
42
44 {
45 Join();
46 }
47
48 bool Start(const std::string& host, uint16 port)
49 {
50 SFSoapRunnable runnable;
51 runnable.SetListenArguments(host, port);
52 return StartWithRunner([runnable]() mutable { runnable.Run(); });
53 }
54
55 bool StartWithRunner(std::function<void()> runner)
56 {
57 if (!runner)
58 return false;
59
60 if (_runner.IsRunning())
61 return false;
62
63 return _runner.Start(std::move(runner)) == 0;
64 }
65
66 void Join()
67 {
68 _runner.Join();
69 }
70
71 bool IsRunning() const
72 {
73 return _runner.IsRunning();
74 }
75
76private:
78
79 SFSoapService(SFSoapService const&) = delete;
81};
82
84{
85public:
87 m_completed(false), m_success(false)
88 {
89 }
90
92 {
93 }
94
95 void appendToPrintBuffer(const char* msg)
96 {
97 m_printBuffer += msg;
98 }
99
100 void wait()
101 {
102 std::unique_lock<std::mutex> lock(m_mutex);
103 m_condition.wait(lock, [this] { return m_completed; });
104 }
105
106 void complete(bool success)
107 {
108 {
109 std::lock_guard<std::mutex> guard(m_mutex);
110 m_success = success;
111 m_completed = true;
112 }
113
114 m_condition.notify_one();
115 }
116
117 void setCommandSuccess(bool val)
118 {
119 m_success = val;
120 }
121
123 {
124 return m_success;
125 }
126
127 static void print(void* callbackArg, const char* msg)
128 {
129 ((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg);
130 }
131
132 static void commandFinished(void* callbackArg, bool success);
133
135 std::string m_printBuffer;
136
137private:
138 std::mutex m_mutex;
139 std::condition_variable m_condition;
141};
142
143#endif
std::uint16_t uint16
Definition Define.h:78
void process_message(struct soap *soap)
Definition SFSoap.cpp:46
std::string _host
Definition SFSoap.h:34
uint16 _port
Definition SFSoap.h:35
void SetListenArguments(const std::string &host, uint16 port)
Definition SFSoap.h:25
bool StartWithRunner(std::function< void()> runner)
Definition SFSoap.h:55
bool IsRunning() const
Definition SFSoap.h:71
SFSoapService(SFSoapService const &)=delete
void Join()
Definition SFSoap.h:66
~SFSoapService()
Definition SFSoap.h:43
SFSoapService()
Definition SFSoap.h:41
bool Start(const std::string &host, uint16 port)
Definition SFSoap.h:48
SFSoapService & operator=(SFSoapService const &)=delete
Skyfire::Asio::IoContextTaskRunner _runner
Definition SFSoap.h:77
void wait()
Definition SFSoap.h:100
std::condition_variable m_condition
Definition SFSoap.h:139
static void commandFinished(void *callbackArg, bool success)
Definition SFSoap.cpp:116
void appendToPrintBuffer(const char *msg)
Definition SFSoap.h:95
bool hasCommandSucceeded() const
Definition SFSoap.h:122
bool m_completed
Definition SFSoap.h:140
std::mutex m_mutex
Definition SFSoap.h:138
SOAPCommand()
Definition SFSoap.h:86
static void print(void *callbackArg, const char *msg)
Definition SFSoap.h:127
std::string m_printBuffer
Definition SFSoap.h:135
bool m_success
Definition SFSoap.h:134
~SOAPCommand()
Definition SFSoap.h:91
void complete(bool success)
Definition SFSoap.h:106
void setCommandSuccess(bool val)
Definition SFSoap.h:117