EchoLib
0.14.0
|
00001 00036 #ifndef ECHOLINK_DIRECTORY_INCLUDED 00037 #define ECHOLINK_DIRECTORY_INCLUDED 00038 00039 00040 /**************************************************************************** 00041 * 00042 * System Includes 00043 * 00044 ****************************************************************************/ 00045 00046 #include <sigc++/sigc++.h> 00047 00048 #include <string> 00049 #include <list> 00050 #include <vector> 00051 #include <iostream> 00052 00053 00054 /**************************************************************************** 00055 * 00056 * Project Includes 00057 * 00058 ****************************************************************************/ 00059 00060 #include <AsyncTcpClient.h> 00061 #include <AsyncTimer.h> 00062 #include <EchoLinkStationData.h> 00063 00064 00065 /**************************************************************************** 00066 * 00067 * Local Includes 00068 * 00069 ****************************************************************************/ 00070 00071 00072 00073 /**************************************************************************** 00074 * 00075 * Forward declarations 00076 * 00077 ****************************************************************************/ 00078 00079 class Cmd; 00080 00081 00082 /**************************************************************************** 00083 * 00084 * Namespace 00085 * 00086 ****************************************************************************/ 00087 00088 namespace EchoLink 00089 { 00090 00091 /**************************************************************************** 00092 * 00093 * Defines & typedefs 00094 * 00095 ****************************************************************************/ 00096 00097 00098 00099 /**************************************************************************** 00100 * 00101 * Exported Global Variables 00102 * 00103 ****************************************************************************/ 00104 00105 00106 00107 /**************************************************************************** 00108 * 00109 * Class definitions 00110 * 00111 ****************************************************************************/ 00112 00125 class Directory : public SigC::Object 00126 { 00127 public: 00128 static const unsigned MAX_DESCRIPTION_SIZE = 27; 00129 00137 Directory(const std::string& server, const std::string& callsign, 00138 const std::string& password, const std::string& description=""); 00139 00143 ~Directory(void); 00144 00152 void makeOnline(void); 00153 00161 void makeBusy(void); 00162 00166 void makeOffline(void); 00167 00171 void refreshRegistration(void) { onRefreshRegistration(0); } 00172 00177 StationData::Status status(void) const { return current_status; } 00178 00184 std::string statusStr(void) const 00185 { 00186 return StationData::statusStr(current_status); 00187 } 00188 00201 void getCalls(void); 00202 00207 void setServer(const std::string& server); 00208 00213 const std::string& server(void) const { return the_server; } 00214 00219 void setCallsign(const std::string& callsign); 00220 00225 const std::string& callsign(void) const { return the_callsign; } 00226 00231 void setPassword(const std::string& password); 00232 00237 const std::string& password(void) const { return the_password; } 00238 00247 void setDescription(const std::string& description); 00248 00253 const std::string& description(void) const { return the_description; } 00254 00263 const std::list<StationData>& links(void) const { return the_links; } 00264 00273 const std::list<StationData>& repeaters(void) const 00274 { 00275 return the_repeaters; 00276 } 00277 00287 const std::list<StationData>& conferences(void) const 00288 { 00289 return the_conferences; 00290 } 00291 00296 const std::list<StationData>& stations(void) const { return the_stations; } 00297 00306 const std::string& message(void) const { return the_message; } 00307 00314 const StationData *findCall(const std::string& call); 00315 00322 const StationData *findStation(int id); 00323 00334 void findStationsByCode(std::vector<StationData> &stns, 00335 const std::string& code, bool exact=true); 00336 00341 SigC::Signal1<void, StationData::Status> statusChanged; 00342 00346 SigC::Signal0<void> stationListUpdated; 00347 00352 SigC::Signal1<void, const std::string&> error; 00353 00354 protected: 00355 00356 private: 00357 typedef enum 00358 { 00359 CS_WAITING_FOR_START, CS_WAITING_FOR_COUNT, CS_WAITING_FOR_CALL, 00360 CS_WAITING_FOR_DATA, CS_WAITING_FOR_ID, CS_WAITING_FOR_IP, 00361 CS_WAITING_FOR_END, CS_IDLE, CS_WAITING_FOR_OK 00362 } ComState; 00363 00364 static const int DIRECTORY_SERVER_PORT = 5200; 00365 static const int REGISTRATION_REFRESH_TIME = 5 * 60 * 1000; // 5 minutes 00366 static const int CMD_TIMEOUT = 120 * 1000; // 2 minutes 00367 00368 ComState com_state; 00369 std::string the_server; 00370 std::string the_callsign; 00371 std::string the_password; 00372 std::string the_description; 00373 std::list<StationData> the_links; 00374 std::list<StationData> the_repeaters; 00375 std::list<StationData> the_stations; 00376 std::list<StationData> the_conferences; 00377 std::string the_message; 00378 std::string error_str; 00379 00380 int get_call_cnt; 00381 StationData get_call_entry; 00382 std::list<StationData> get_call_list; 00383 00384 Async::TcpClient * ctrl_con; 00385 std::list<Cmd> cmd_queue; 00386 StationData::Status the_status; 00387 Async::Timer * reg_refresh_timer; 00388 StationData::Status current_status; 00389 bool server_changed; 00390 Async::Timer * cmd_timer; 00391 00392 Directory(const Directory&); 00393 Directory& operator =(const Directory&); 00394 00395 void printBuf(const unsigned char *buf, int len); 00396 int handleCallList(char *buf, int len); 00397 00398 void ctrlSockConnected(void); 00399 void ctrlSockDisconnected(Async::TcpConnection *con, 00400 Async::TcpClient::DisconnectReason reason); 00401 int ctrlSockDataReceived(Async::TcpConnection *con, void *ptr, int len); 00402 void sendNextCmd(void); 00403 void addCmdToQueue(Cmd cmd); 00404 void setStatus(StationData::Status new_status); 00405 void createClientObject(void); 00406 void onRefreshRegistration(Async::Timer *timer); 00407 void onCmdTimeout(Async::Timer *timer); 00408 bool stationCodeEq(const StationData& stn, std::string code, bool exact); 00409 00410 }; /* class Directory */ 00411 00412 00413 std::ostream& operator<<(std::ostream& os, const StationData& station); 00414 00415 00416 } /* namespace */ 00417 00418 00419 #endif /* ECHOLINK_DIRECTORY_INCLUDED */ 00420 00421 00422 00423 /* 00424 * This file has not been truncated 00425 */ 00426