Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
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
"
10
#include "
Threading/BoostAsioTaskRunner.h
"
11
12
#include <condition_variable>
13
#include <functional>
14
#include <mutex>
15
#include <string>
16
#include <utility>
17
18
class
SFSoapRunnable
19
{
20
public
:
21
SFSoapRunnable
() :
_port
(0) { }
22
23
void
Run
();
24
25
void
SetListenArguments
(
const
std::string& host,
uint16
port)
26
{
27
_host
= host;
28
_port
= port;
29
}
30
31
private
:
32
void
process_message
(
struct
soap* soap);
33
34
std::string
_host
;
35
uint16
_port
;
36
};
37
38
class
SFSoapService
39
{
40
public
:
41
SFSoapService
() { }
42
43
~SFSoapService
()
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
76
private
:
77
Skyfire::Asio::IoContextTaskRunner
_runner
;
78
79
SFSoapService
(
SFSoapService
const
&) =
delete
;
80
SFSoapService
&
operator=
(
SFSoapService
const
&) =
delete
;
81
};
82
83
class
SOAPCommand
84
{
85
public
:
86
SOAPCommand
() :
87
m_completed
(false),
m_success
(false)
88
{
89
}
90
91
~SOAPCommand
()
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
122
bool
hasCommandSucceeded
()
const
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
134
bool
m_success
;
135
std::string
m_printBuffer
;
136
137
private
:
138
std::mutex
m_mutex
;
139
std::condition_variable
m_condition
;
140
bool
m_completed
;
141
};
142
143
#endif
BoostAsioTaskRunner.h
Define.h
uint16
std::uint16_t uint16
Definition
Define.h:78
SFSoapRunnable
Definition
SFSoap.h:19
SFSoapRunnable::process_message
void process_message(struct soap *soap)
Definition
SFSoap.cpp:46
SFSoapRunnable::_host
std::string _host
Definition
SFSoap.h:34
SFSoapRunnable::SFSoapRunnable
SFSoapRunnable()
Definition
SFSoap.h:21
SFSoapRunnable::_port
uint16 _port
Definition
SFSoap.h:35
SFSoapRunnable::SetListenArguments
void SetListenArguments(const std::string &host, uint16 port)
Definition
SFSoap.h:25
SFSoapRunnable::Run
void Run()
Definition
SFSoap.cpp:13
SFSoapService::StartWithRunner
bool StartWithRunner(std::function< void()> runner)
Definition
SFSoap.h:55
SFSoapService::IsRunning
bool IsRunning() const
Definition
SFSoap.h:71
SFSoapService::SFSoapService
SFSoapService(SFSoapService const &)=delete
SFSoapService::Join
void Join()
Definition
SFSoap.h:66
SFSoapService::~SFSoapService
~SFSoapService()
Definition
SFSoap.h:43
SFSoapService::SFSoapService
SFSoapService()
Definition
SFSoap.h:41
SFSoapService::Start
bool Start(const std::string &host, uint16 port)
Definition
SFSoap.h:48
SFSoapService::operator=
SFSoapService & operator=(SFSoapService const &)=delete
SFSoapService::_runner
Skyfire::Asio::IoContextTaskRunner _runner
Definition
SFSoap.h:77
SOAPCommand::wait
void wait()
Definition
SFSoap.h:100
SOAPCommand::m_condition
std::condition_variable m_condition
Definition
SFSoap.h:139
SOAPCommand::commandFinished
static void commandFinished(void *callbackArg, bool success)
Definition
SFSoap.cpp:116
SOAPCommand::appendToPrintBuffer
void appendToPrintBuffer(const char *msg)
Definition
SFSoap.h:95
SOAPCommand::hasCommandSucceeded
bool hasCommandSucceeded() const
Definition
SFSoap.h:122
SOAPCommand::m_completed
bool m_completed
Definition
SFSoap.h:140
SOAPCommand::m_mutex
std::mutex m_mutex
Definition
SFSoap.h:138
SOAPCommand::SOAPCommand
SOAPCommand()
Definition
SFSoap.h:86
SOAPCommand::print
static void print(void *callbackArg, const char *msg)
Definition
SFSoap.h:127
SOAPCommand::m_printBuffer
std::string m_printBuffer
Definition
SFSoap.h:135
SOAPCommand::m_success
bool m_success
Definition
SFSoap.h:134
SOAPCommand::~SOAPCommand
~SOAPCommand()
Definition
SFSoap.h:91
SOAPCommand::complete
void complete(bool success)
Definition
SFSoap.h:106
SOAPCommand::setCommandSuccess
void setCommandSuccess(bool val)
Definition
SFSoap.h:117
Skyfire::Asio::IoContextTaskRunner
Definition
BoostAsioTaskRunner.h:20
src
server
worldserver
SFSoap
SFSoap.h
Generated on
for Project SkyFire Core by
1.17.0