EchoLib  0.14.0
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 
79 class Cmd;
80 
81 
82 /****************************************************************************
83  *
84  * Namespace
85  *
86  ****************************************************************************/
87 
88 namespace EchoLink
89 {
90 
91 /****************************************************************************
92  *
93  * Defines & typedefs
94  *
95  ****************************************************************************/
96 
97 
98 
99 /****************************************************************************
100  *
101  * Exported Global Variables
102  *
103  ****************************************************************************/
104 
105 
106 
107 /****************************************************************************
108  *
109  * Class definitions
110  *
111  ****************************************************************************/
112 
125 class Directory : public SigC::Object
126 {
127  public:
128  static const unsigned MAX_DESCRIPTION_SIZE = 27;
129 
137  Directory(const std::string& server, const std::string& callsign,
138  const std::string& password, const std::string& description="");
139 
143  ~Directory(void);
144 
152  void makeOnline(void);
153 
161  void makeBusy(void);
162 
166  void makeOffline(void);
167 
171  void refreshRegistration(void) { onRefreshRegistration(0); }
172 
177  StationData::Status status(void) const { return current_status; }
178 
184  std::string statusStr(void) const
185  {
186  return StationData::statusStr(current_status);
187  }
188 
201  void getCalls(void);
202 
207  void setServer(const std::string& server);
208 
213  const std::string& server(void) const { return the_server; }
214 
219  void setCallsign(const std::string& callsign);
220 
225  const std::string& callsign(void) const { return the_callsign; }
226 
231  void setPassword(const std::string& password);
232 
237  const std::string& password(void) const { return the_password; }
238 
247  void setDescription(const std::string& description);
248 
253  const std::string& description(void) const { return the_description; }
254 
263  const std::list<StationData>& links(void) const { return the_links; }
264 
273  const std::list<StationData>& repeaters(void) const
274  {
275  return the_repeaters;
276  }
277 
287  const std::list<StationData>& conferences(void) const
288  {
289  return the_conferences;
290  }
291 
296  const std::list<StationData>& stations(void) const { return the_stations; }
297 
306  const std::string& message(void) const { return the_message; }
307 
314  const StationData *findCall(const std::string& call);
315 
322  const StationData *findStation(int id);
323 
334  void findStationsByCode(std::vector<StationData> &stns,
335  const std::string& code, bool exact=true);
336 
341  SigC::Signal1<void, StationData::Status> statusChanged;
342 
346  SigC::Signal0<void> stationListUpdated;
347 
352  SigC::Signal1<void, const std::string&> error;
353 
354  protected:
355 
356  private:
357  typedef enum
358  {
359  CS_WAITING_FOR_START, CS_WAITING_FOR_COUNT, CS_WAITING_FOR_CALL,
360  CS_WAITING_FOR_DATA, CS_WAITING_FOR_ID, CS_WAITING_FOR_IP,
361  CS_WAITING_FOR_END, CS_IDLE, CS_WAITING_FOR_OK
362  } ComState;
363 
364  static const int DIRECTORY_SERVER_PORT = 5200;
365  static const int REGISTRATION_REFRESH_TIME = 5 * 60 * 1000; // 5 minutes
366  static const int CMD_TIMEOUT = 120 * 1000; // 2 minutes
367 
368  ComState com_state;
369  std::string the_server;
370  std::string the_callsign;
371  std::string the_password;
372  std::string the_description;
373  std::list<StationData> the_links;
374  std::list<StationData> the_repeaters;
375  std::list<StationData> the_stations;
376  std::list<StationData> the_conferences;
377  std::string the_message;
378  std::string error_str;
379 
380  int get_call_cnt;
381  StationData get_call_entry;
382  std::list<StationData> get_call_list;
383 
384  Async::TcpClient * ctrl_con;
385  std::list<Cmd> cmd_queue;
386  StationData::Status the_status;
387  Async::Timer * reg_refresh_timer;
388  StationData::Status current_status;
389  bool server_changed;
390  Async::Timer * cmd_timer;
391 
392  Directory(const Directory&);
393  Directory& operator =(const Directory&);
394 
395  void printBuf(const unsigned char *buf, int len);
396  int handleCallList(char *buf, int len);
397 
398  void ctrlSockConnected(void);
399  void ctrlSockDisconnected(Async::TcpConnection *con,
400  Async::TcpClient::DisconnectReason reason);
401  int ctrlSockDataReceived(Async::TcpConnection *con, void *ptr, int len);
402  void sendNextCmd(void);
403  void addCmdToQueue(Cmd cmd);
404  void setStatus(StationData::Status new_status);
405  void createClientObject(void);
406  void onRefreshRegistration(Async::Timer *timer);
407  void onCmdTimeout(Async::Timer *timer);
408  bool stationCodeEq(const StationData& stn, std::string code, bool exact);
409 
410 }; /* class Directory */
411 
412 
413 std::ostream& operator<<(std::ostream& os, const StationData& station);
414 
415 
416 } /* namespace */
417 
418 
419 #endif /* ECHOLINK_DIRECTORY_INCLUDED */
420 
421 
422 
423 /*
424  * This file has not been truncated
425  */
426 
Contains a class that represent station data.