EchoLib 1.3.5
EchoLinkDirectory.h
Go to the documentation of this file.
1
36#ifndef ECHOLINK_DIRECTORY_INCLUDED
37#define ECHOLINK_DIRECTORY_INCLUDED
38
39
40/****************************************************************************
41 *
42 * System Includes
43 *
44 ****************************************************************************/
45
46#include <sigc++/sigc++.h>
47
48#include <string>
49#include <list>
50#include <vector>
51#include <iostream>
52
53
54/****************************************************************************
55 *
56 * Project Includes
57 *
58 ****************************************************************************/
59
60#include <AsyncTcpClient.h>
61#include <AsyncTimer.h>
62#include <EchoLinkStationData.h>
63
64
65/****************************************************************************
66 *
67 * Local Includes
68 *
69 ****************************************************************************/
70
71
72
73/****************************************************************************
74 *
75 * Forward declarations
76 *
77 ****************************************************************************/
78
79class Cmd;
80
81namespace EchoLink
82{
83 class DirectoryCon;
84};
85
86
87/****************************************************************************
88 *
89 * Namespace
90 *
91 ****************************************************************************/
92
93namespace EchoLink
94{
95
96/****************************************************************************
97 *
98 * Defines & typedefs
99 *
100 ****************************************************************************/
101
102
103
104/****************************************************************************
105 *
106 * Exported Global Variables
107 *
108 ****************************************************************************/
109
110
111
112/****************************************************************************
113 *
114 * Class definitions
115 *
116 ****************************************************************************/
117
130class Directory : public sigc::trackable
131{
132 public:
133 static const unsigned MAX_DESCRIPTION_SIZE = 27;
134
143 Directory(const std::vector<std::string>& servers,
144 const std::string& callsign,
145 const std::string& password, const std::string& description="",
146 const Async::IpAddress &bind_ip=Async::IpAddress());
147
152
160 void makeOnline(void);
161
169 void makeBusy(void);
170
174 void makeOffline(void);
175
179 void refreshRegistration(void) { onRefreshRegistration(0); }
180
185 StationData::Status status(void) const { return current_status; }
186
192 std::string statusStr(void) const
193 {
194 return StationData::statusStr(current_status);
195 }
196
209 void getCalls(void);
210
215 void setServers(const std::vector<std::string>& servers);
216
221 const std::vector<std::string>& servers(void) const { return the_servers; }
222
227 void setCallsign(const std::string& callsign);
228
233 const std::string& callsign(void) const { return the_callsign; }
234
239 void setPassword(const std::string& password);
240
245 const std::string& password(void) const { return the_password; }
246
255 void setDescription(const std::string& description);
256
261 const std::string& description(void) const { return the_description; }
262
271 const std::list<StationData>& links(void) const { return the_links; }
272
281 const std::list<StationData>& repeaters(void) const
282 {
283 return the_repeaters;
284 }
285
295 const std::list<StationData>& conferences(void) const
296 {
297 return the_conferences;
298 }
299
304 const std::list<StationData>& stations(void) const { return the_stations; }
305
314 const std::string& message(void) const { return the_message; }
315
322 const StationData *findCall(const std::string& call);
323
330 const StationData *findStation(int id);
331
342 void findStationsByCode(std::vector<StationData> &stns,
343 const std::string& code, bool exact=true);
344
349 sigc::signal<void, StationData::Status> statusChanged;
350
354 sigc::signal<void> stationListUpdated;
355
360 sigc::signal<void, const std::string&> error;
361
362 protected:
363
364 private:
365 typedef enum
366 {
367 CS_WAITING_FOR_START, CS_WAITING_FOR_COUNT, CS_WAITING_FOR_CALL,
368 CS_WAITING_FOR_DATA, CS_WAITING_FOR_ID, CS_WAITING_FOR_IP,
369 CS_WAITING_FOR_END, CS_IDLE, CS_WAITING_FOR_OK
370 } ComState;
371
372 static const int DIRECTORY_SERVER_PORT = 5200;
373 static const int REGISTRATION_REFRESH_TIME = 5 * 60 * 1000; // 5 minutes
374 static const int CMD_TIMEOUT = 120 * 1000; // 2 minutes
375
376 ComState com_state;
377 std::vector<std::string> the_servers;
378 std::string the_callsign;
379 std::string the_password;
380 std::string the_description;
381 std::list<StationData> the_links;
382 std::list<StationData> the_repeaters;
383 std::list<StationData> the_stations;
384 std::list<StationData> the_conferences;
385 std::string the_message;
386 std::string error_str;
387
388 int get_call_cnt;
389 StationData get_call_entry;
390 std::list<StationData> get_call_list;
391
392 DirectoryCon * ctrl_con;
393 std::list<Cmd> cmd_queue;
394 StationData::Status the_status;
395 Async::Timer * reg_refresh_timer;
396 StationData::Status current_status;
397 bool server_changed;
398 Async::Timer * cmd_timer;
399 Async::IpAddress bind_ip;
400
401 Directory(const Directory&);
402 Directory& operator =(const Directory&);
403
404 void printBuf(const unsigned char *buf, int len);
405 int handleCallList(char *buf, int len);
406
407 void ctrlSockReady(bool is_ready);
408 void ctrlSockConnected(void);
409 void ctrlSockDisconnected(void);
410 int ctrlSockDataReceived(void *ptr, unsigned len);
411 void sendNextCmd(void);
412 void addCmdToQueue(Cmd cmd);
413 void setStatus(StationData::Status new_status);
414 void createClientObject(void);
415 void onRefreshRegistration(Async::Timer *timer);
416 void onCmdTimeout(Async::Timer *timer);
417 bool stationCodeEq(const StationData& stn, std::string code, bool exact);
418
419}; /* class Directory */
420
421
422std::ostream& operator<<(std::ostream& os, const StationData& station);
423
424
425} /* namespace */
426
427
428#endif /* ECHOLINK_DIRECTORY_INCLUDED */
429
430
431
432/*
433 * This file has not been truncated
434 */
435
Contains a class that represent station data.