~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to src/server/xml_server.cxx

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-10-25 11:17:10 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141025111710-n32skgya3l9u1brw
Tags: 1.3.17-1
* New upstream release (Closes: #761839)
* Debian Standards-Version: 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ---------------------------------------------------------------------
 
2
//
 
3
//      xml_server.cxx, a part of flrig
 
4
//
 
5
// Copyright (C) 2014
 
6
//               Dave Freese, W1HKJ
 
7
//
 
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.
 
12
//
 
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.
 
17
//
 
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
 
20
// Foundation, Inc.
 
21
// 59 Temple Place, Suite 330
 
22
// Boston, MA  02111-1307 USA
 
23
//
 
24
// ---------------------------------------------------------------------
 
25
 
 
26
#include <stdlib.h>
 
27
#include <iostream>
 
28
#include <fstream>
 
29
#include <vector>
 
30
#include <sys/types.h>
 
31
#include <sys/stat.h>
 
32
#include <stdlib.h>
 
33
#include <stdio.h>
 
34
#include <fcntl.h>
 
35
#include <pthread.h>
 
36
 
 
37
#include <FL/Fl.H>
 
38
#include <FL/Fl_Box.H>
 
39
#include <FL/Enumerations.H>
 
40
 
 
41
#include "support.h"
 
42
#include "debug.h"
 
43
 
 
44
#include "XmlRpc.h"
 
45
 
 
46
using namespace XmlRpc;
 
47
 
 
48
// The server
 
49
XmlRpcServer s;
 
50
 
 
51
/*
 
52
// Request record if it exists else return "NO_RECORD"
 
53
// Returns ADIF record
 
54
class log_get_record : public XmlRpcServerMethod
 
55
{
 
56
public:
 
57
  log_get_record(XmlRpcServer* s) : XmlRpcServerMethod("log.get_record", s) {}
 
58
 
 
59
  void execute(XmlRpcValue& params, XmlRpcValue& result)
 
60
  {
 
61
        std::string callsign = std::string(params[0]);
 
62
    std::string resultString = fetch_record(callsign.c_str());
 
63
        result = resultString;
 
64
  }
 
65
 
 
66
  std::string help() { return std::string("log.get_record CALL"); }
 
67
 
 
68
} log_get_record(&s);    // This constructor registers the method with the server
 
69
 
 
70
// Arguments: CALLSIGN MODE TIME_SPAN FREQ
 
71
class log_check_dup : public XmlRpcServerMethod
 
72
{
 
73
public:
 
74
  log_check_dup(XmlRpcServer* s) : XmlRpcServerMethod("log.check_dup", s) {}
 
75
 
 
76
  void execute(XmlRpcValue& params, XmlRpcValue& result)
 
77
  {
 
78
        if (params.size() != 6) {
 
79
                result = "Wrong # parameters";
 
80
                return;
 
81
        }
 
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(
 
96
                        callsign.c_str(),
 
97
                        (const char *)szDate(6), (const char *)szTime(0), (unsigned int)ispn, bspn,
 
98
                        freq.c_str(), bfreq,
 
99
                        state.c_str(), bstate,
 
100
                        mode.c_str(), bmode,
 
101
                        xchg_in.c_str(), bxchg);
 
102
        result = (res ? "true" : "false");
 
103
        }
 
104
 
 
105
        std::string help() { 
 
106
                return std::string("log.check_dup CALL, MODE(0), TIME_SPAN(0), FREQ_HZ(0), STATE(0), XCHG_IN(0)"); 
 
107
        }
 
108
 
 
109
} log_check_dup(&s);
 
110
 
 
111
void updateBrowser(void *)
 
112
{
 
113
        loadBrowser(false);
 
114
}
 
115
*/
 
116
 
 
117
class rig_get_vfoA : public XmlRpcServerMethod
 
118
{
 
119
public:
 
120
  rig_get_vfoA(XmlRpcServer* s) : XmlRpcServerMethod("rig.get_vfoA") {}
 
121
 
 
122
  void execute(XmlRpcValue& params, XmlRpcValue& result)
 
123
  {
 
124
//    std::string adif_record = std::string(params[0]);
 
125
//      xml_adif.add_record(adif_record.c_str(), qsodb);
 
126
//      Fl::awake(updateBrowser);
 
127
  }
 
128
        std::string help() { return std::string("rig.get_vfoA(Hz)"); }
 
129
 
 
130
} rig_get_vfoA(&s);
 
131
 
 
132
class rig_set_vfoA : public XmlRpcServerMethod
 
133
{
 
134
public:
 
135
  rig_set_vfoA(XmlRpcServer* s) : XmlRpcServerMethod("rig.set_vfoA", s) {}
 
136
 
 
137
  void execute(XmlRpcValue& params, XmlRpcValue& result)
 
138
  {
 
139
//    std::string adif_record = std::string(params[0]);
 
140
//      xml_adif.add_record(adif_record.c_str(), qsodb);
 
141
//      Fl::awake(updateBrowser);
 
142
  }
 
143
        std::string help() { return std::string("rig.set_vfoA NNNNNNNN (Hz)"); }
 
144
 
 
145
} rig_set_vfoA(&s);
 
146
 
 
147
pthread_t *xml_thread = 0;
 
148
 
 
149
void * xml_thread_loop(void *d)
 
150
{
 
151
        for(;;) {
 
152
                s.work(-1.0);
 
153
        }
 
154
        return NULL;
 
155
}
 
156
 
 
157
void start_server(int port)
 
158
{
 
159
        XmlRpc::setVerbosity(0);
 
160
 
 
161
// Create the server socket on the specified port
 
162
        s.bindAndListen(port);
 
163
 
 
164
// Enable introspection
 
165
        s.enableIntrospection(true);
 
166
 
 
167
        xml_thread = new pthread_t;
 
168
        if (pthread_create(xml_thread, NULL, xml_thread_loop, NULL)) {
 
169
                perror("pthread_create");
 
170
                exit(EXIT_FAILURE);
 
171
        }
 
172
}
 
173
 
 
174
void exit_server()
 
175
{
 
176
        s.exit();
 
177
}
 
178
 
 
179