1
// ---------------------------------------------------------------------
3
// xml_server.cxx, a part of flrig
8
// This library is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 3 of the License, or
11
// (at your option) any later version.
13
// This library is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
18
// You should have received a copy of the GNU General Public License
19
// along with the program; if not, write to the Free Software
21
// 59 Temple Place, Suite 330
22
// Boston, MA 02111-1307 USA
24
// ---------------------------------------------------------------------
30
#include <sys/types.h>
38
#include <FL/Fl_Box.H>
39
#include <FL/Enumerations.H>
46
using namespace XmlRpc;
52
// Request record if it exists else return "NO_RECORD"
53
// Returns ADIF record
54
class log_get_record : public XmlRpcServerMethod
57
log_get_record(XmlRpcServer* s) : XmlRpcServerMethod("log.get_record", s) {}
59
void execute(XmlRpcValue& params, XmlRpcValue& result)
61
std::string callsign = std::string(params[0]);
62
std::string resultString = fetch_record(callsign.c_str());
63
result = resultString;
66
std::string help() { return std::string("log.get_record CALL"); }
68
} log_get_record(&s); // This constructor registers the method with the server
70
// Arguments: CALLSIGN MODE TIME_SPAN FREQ
71
class log_check_dup : public XmlRpcServerMethod
74
log_check_dup(XmlRpcServer* s) : XmlRpcServerMethod("log.check_dup", s) {}
76
void execute(XmlRpcValue& params, XmlRpcValue& result)
78
if (params.size() != 6) {
79
result = "Wrong # parameters";
82
std::string callsign = std::string(params[0]);
83
std::string mode = std::string(params[1]);
84
std::string spn = std::string(params[2]);
85
std::string freq = std::string(params[3]);
86
std::string state = std::string(params[4]);
87
std::string xchg_in = std::string(params[5]);
88
int ispn = atoi(spn.c_str());
89
int ifreq = atoi(freq.c_str());
90
bool bspn = (ispn > 0);
91
bool bfreq = (ifreq > 0);
92
bool bmode = (mode != "0");
93
bool bstate = (state != "0");
94
bool bxchg = (xchg_in != "0");
95
bool res = qsodb.duplicate(
97
(const char *)szDate(6), (const char *)szTime(0), (unsigned int)ispn, bspn,
99
state.c_str(), bstate,
101
xchg_in.c_str(), bxchg);
102
result = (res ? "true" : "false");
106
return std::string("log.check_dup CALL, MODE(0), TIME_SPAN(0), FREQ_HZ(0), STATE(0), XCHG_IN(0)");
111
void updateBrowser(void *)
117
class rig_get_vfoA : public XmlRpcServerMethod
120
rig_get_vfoA(XmlRpcServer* s) : XmlRpcServerMethod("rig.get_vfoA") {}
122
void execute(XmlRpcValue& params, XmlRpcValue& result)
124
// std::string adif_record = std::string(params[0]);
125
// xml_adif.add_record(adif_record.c_str(), qsodb);
126
// Fl::awake(updateBrowser);
128
std::string help() { return std::string("rig.get_vfoA(Hz)"); }
132
class rig_set_vfoA : public XmlRpcServerMethod
135
rig_set_vfoA(XmlRpcServer* s) : XmlRpcServerMethod("rig.set_vfoA", s) {}
137
void execute(XmlRpcValue& params, XmlRpcValue& result)
139
// std::string adif_record = std::string(params[0]);
140
// xml_adif.add_record(adif_record.c_str(), qsodb);
141
// Fl::awake(updateBrowser);
143
std::string help() { return std::string("rig.set_vfoA NNNNNNNN (Hz)"); }
147
pthread_t *xml_thread = 0;
149
void * xml_thread_loop(void *d)
157
void start_server(int port)
159
XmlRpc::setVerbosity(0);
161
// Create the server socket on the specified port
162
s.bindAndListen(port);
164
// Enable introspection
165
s.enableIntrospection(true);
167
xml_thread = new pthread_t;
168
if (pthread_create(xml_thread, NULL, xml_thread_loop, NULL)) {
169
perror("pthread_create");