00001
00036 #ifndef ECHOLINK_DIRECTORY_INCLUDED
00037 #define ECHOLINK_DIRECTORY_INCLUDED
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include <sigc++/signal_system.h>
00047
00048 #include <string>
00049 #include <list>
00050 #include <vector>
00051
00052
00053
00054
00055
00056
00057
00058
00059 #include <AsyncTcpClient.h>
00060 #include <AsyncTimer.h>
00061 #include <EchoLinkStationData.h>
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 class Cmd;
00079
00080
00081
00082
00083
00084
00085
00086
00087 namespace EchoLink
00088 {
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00124 class Directory : public SigC::Object
00125 {
00126 public:
00127 static const unsigned MAX_DESCRIPTION_SIZE = 27;
00128
00136 Directory(const std::string& server, const std::string& callsign,
00137 const std::string& password, const std::string& description="");
00138
00142 ~Directory(void);
00143
00151 void makeOnline(void);
00152
00160 void makeBusy(void);
00161
00165 void makeOffline(void);
00166
00170 void refreshRegistration(void) { onRefreshRegistration(0); }
00171
00176 StationData::Status status(void) const { return current_status; }
00177
00183 std::string statusStr(void) const
00184 {
00185 return StationData::statusStr(current_status);
00186 }
00187
00200 void getCalls(void);
00201
00206 void setServer(const std::string& server);
00207
00212 const std::string& server(void) const { return the_server; }
00213
00218 void setCallsign(const std::string& callsign);
00219
00224 const std::string& callsign(void) const { return the_callsign; }
00225
00230 void setPassword(const std::string& password);
00231
00236 const std::string& password(void) const { return the_password; }
00237
00246 void setDescription(const std::string& description);
00247
00252 const std::string& description(void) const { return the_description; }
00253
00262 const std::list<StationData>& links(void) const { return the_links; }
00263
00272 const std::list<StationData>& repeaters(void) const
00273 {
00274 return the_repeaters;
00275 }
00276
00286 const std::list<StationData>& conferences(void) const
00287 {
00288 return the_conferences;
00289 }
00290
00295 const std::list<StationData>& stations(void) const { return the_stations; }
00296
00305 const std::string& message(void) const { return the_message; }
00306
00313 const StationData *findCall(const std::string& call);
00314
00321 const StationData *findStation(int id);
00322
00333 void findStationsByCode(std::vector<StationData> &stns,
00334 const std::string& code, bool exact=true);
00335
00340 SigC::Signal1<void, StationData::Status> statusChanged;
00341
00345 SigC::Signal0<void> stationListUpdated;
00346
00351 SigC::Signal1<void, const std::string&> error;
00352
00353 protected:
00354
00355 private:
00356 typedef enum
00357 {
00358 CS_WAITING_FOR_START, CS_WAITING_FOR_COUNT, CS_WAITING_FOR_CALL,
00359 CS_WAITING_FOR_DATA, CS_WAITING_FOR_ID, CS_WAITING_FOR_IP,
00360 CS_WAITING_FOR_END, CS_IDLE, CS_WAITING_FOR_OK
00361 } ComState;
00362
00363 static const int DIRECTORY_SERVER_PORT = 5200;
00364 static const int REGISTRATION_REFRESH_TIME = 5 * 60 * 1000;
00365 static const int CMD_TIMEOUT = 120 * 1000;
00366
00367 ComState com_state;
00368 std::string the_server;
00369 std::string the_callsign;
00370 std::string the_password;
00371 std::string the_description;
00372 std::list<StationData> the_links;
00373 std::list<StationData> the_repeaters;
00374 std::list<StationData> the_stations;
00375 std::list<StationData> the_conferences;
00376 std::string the_message;
00377 std::string error_str;
00378
00379 int get_call_cnt;
00380 StationData get_call_entry;
00381 std::list<StationData> get_call_list;
00382
00383 Async::TcpClient * ctrl_con;
00384 std::list<Cmd> cmd_queue;
00385 StationData::Status the_status;
00386 Async::Timer * reg_refresh_timer;
00387 StationData::Status current_status;
00388 bool server_changed;
00389 Async::Timer * cmd_timer;
00390
00391 Directory(const Directory&);
00392 Directory& operator =(const Directory&);
00393
00394 void printBuf(const unsigned char *buf, int len);
00395 int handleCallList(char *buf, int len);
00396
00397 void ctrlSockConnected(void);
00398 void ctrlSockDisconnected(Async::TcpConnection *con,
00399 Async::TcpClient::DisconnectReason reason);
00400 int ctrlSockDataReceived(Async::TcpConnection *con, void *ptr, int len);
00401 void sendNextCmd(void);
00402 void addCmdToQueue(Cmd cmd);
00403 void setStatus(StationData::Status new_status);
00404 void createClientObject(void);
00405 void onRefreshRegistration(Async::Timer *timer);
00406 void onCmdTimeout(Async::Timer *timer);
00407 bool stationCodeEq(const StationData& stn, std::string code, bool exact);
00408
00409 };
00410
00411
00412 }
00413
00414
00415 #endif
00416
00417
00418
00419
00420
00421
00422