/* User manager class needs to handle user communication. Will run a thread that listens for connections and then spawns new threads to handle the communications from them. LOGIN command handling will be cause the login manager handler thread to find a position in the users list for them, the users list is unordered but using the GetClosest method you can retrieve the user that is closest to a given user. The static GetDistance method can then be used to find the distance between the closest users two neighbours and the given user. Database handling will be done through a secondary helper class. A UserData object will be created by these methods that can be used to validate and create a UserData object from a username/password. Classes required: UserManager : wxThread - starts a socket server and listens for users ConnectionHandler : wxThread - handles a socket from a user UserDatabase : wxDbTable - gets UserData from the db. */ #ifndef MANAGING_TO_USE_ME #define MANAGING_TO_USE_ME #include "common.h" #include #include #include #include #include #include "network.h" #include "database.h" #include "users.h" #include "heartbeat.h" #include "MutexLocker.h" using namespace std; using namespace Network; using namespace Database; namespace UserManagement { class UserHandler; typedef wxString (*callback) (UserHandler *handle, const wxString&); typedef struct { wxString sCommand; // the command wxString sHelp; // the help message callback function; // the function } callBackFunction; typedef vector callbackVector; typedef struct { wxString sEventType; wxString sArgs; UserData *data1; UserData *data2; } UserEvent; typedef vector eventQueue; class UserManager : public wxThread { public: UserManager(); ~UserManager(); wxThread::ExitCode Entry(); void QueueEvent(UserEvent event); static UserManager * getManager(); private: void ProcessEvents(); eventQueue queue; static UserManager *mgr; BeatMonitor *monitor; // possible requirement for a vector of child threads? // queue of UserEvent objects }; class UserHandler : public wxThread { public: UserHandler(TCP_socket m_socket); ~UserHandler(); //wxString (*func)(UserHandler *handle, const wxString&) wxThread::ExitCode Entry(); static bool RegisterCmd(callback, const wxString& sCommand, const wxString& sHelp); static callbackVector functions; static wxString login(UserHandler *handle, const wxString &args); static wxString logout(UserHandler *handle, const wxString &args); static wxString src(UserHandler *handle, const wxString &args); static wxString dst(UserHandler *handle, const wxString &args); static wxString port(UserHandler *handle, const wxString &args); static wxString ping(UserHandler *handle, const wxString &args); static wxString reg(UserHandler *handle,const wxString &args); static wxString stats(UserHandler *handle,const wxString &args); static wxString status(UserHandler *handle,const wxString &args); TCP_socket socket; private: Database::UserTable *table; UserData *data; static callback MatchFunction( const wxString& sCommand , wxString& sArgs ); bool valid; bool loggedIn; }; } #endif