#ifndef SERVER_H_INCLUDED #define SERVER_H_INCLUDED #include #include #include #include "boost/shared_array.hpp" #include "boost/property_tree/ptree.hpp" #include "boost/foreach.hpp" #include "boost/asio.hpp" #include "boost/date_time/posix_time/posix_time.hpp" #include "boost/signal.hpp" #include "boost/variant.hpp" #include "include/Utils/Network/SignalSender.h" namespace SE { class TAutorizatorInterface { protected: public: virtual void StartListen() = 0; virtual ~TAutorizatorInterface() { } }; class TSimpleAutorizator : public TAutorizatorInterface { protected: static std::vector UserPasswords; static boost::mutex UserPasswordsMutex; public: boost::asio::io_service& IoService; boost::asio::ip::tcp::socket& Socket; TSimpleAutorizator(boost::asio::io_service& ioService, boost::asio::ip::tcp::socket& socket); virtual void StartListen(); void HandleGetData(boost::property_tree::ptree pTree); boost::signal ErrorSignal; boost::signal AllowedSignal; boost::signal DeniedSignal; }; typedef boost::variant> TAuthorizatorVariant; class TServerSocket; class TConnectedUser : public boost::enable_shared_from_this { protected: TServerSocket& Server; std::string Login; //Need to generalize this public: boost::asio::ip::tcp::socket Socket; TAuthorizatorVariant Autorizator; boost::shared_ptr UserDataReader; TConnectedUser(TServerSocket& server); ~TConnectedUser(); std::string GetLogin() { return Login; } void HandleAllowed(std::string login); //Need to generalize this void SendPropertyTree(boost::property_tree::ptree pTree); void DisconnectSlots(); }; class TServerSocket { protected: std::vector> UserArr; boost::thread ServiceThread; std::shared_ptr Acceptor; public: boost::asio::io_service IoService; TServerSocket(); ~TServerSocket(); void Open(int port); void Close(); void UpdateInThread(); void JoinServiceThread(); void StartAccept(); void HandleAccept(boost::shared_ptr user, const boost::system::error_code& error); void DeleteUser(boost::shared_ptr user); //Need to generalize this boost::signal)> OnUserAuthorizedSignal; boost::signal)> OnUserDisconnectedSignal; }; } //namespace SE #endif