Update CMake configuration and refactor code to use smart pointers for memory management
This commit is contained in:
12
user.h
12
user.h
@@ -11,7 +11,7 @@ namespace Yc {
|
||||
|
||||
class Room;
|
||||
|
||||
class User: public Base {
|
||||
class User: public Base, public std::enable_shared_from_this<User> {
|
||||
public:
|
||||
enum MsgType {
|
||||
error = -1,
|
||||
@@ -26,26 +26,26 @@ namespace Yc {
|
||||
result = 9
|
||||
};
|
||||
|
||||
User(Room *parent, std::string name, std::string color, int socket);
|
||||
User(std::shared_ptr<Room> parent, std::string name, std::string color, int socket);
|
||||
~User();
|
||||
std::string name() const;
|
||||
bool validateToken(std::string token);
|
||||
bool isUser(User *toValidate);
|
||||
bool isUser(std::shared_ptr<User> toValidate);
|
||||
void sendMsg(MsgType type, std::string message, std::string userName, std::string color);
|
||||
void sendMsg(MsgType type, const char *message, std::string userName, std::string color);
|
||||
void sendMsg(MsgType type, Json::Value message, std::string userName, std::string color);
|
||||
void checkerTask();
|
||||
void stop();
|
||||
std::string color() const;
|
||||
void setParent(Room *parent);
|
||||
void setParent(std::shared_ptr<Room> parent);
|
||||
private:
|
||||
Room *_parent;
|
||||
std::shared_ptr<Room> _parent;
|
||||
std::string _name;
|
||||
std::string _color;
|
||||
int _socket;
|
||||
std::string _token;
|
||||
bool _stop;
|
||||
std::thread *thread;
|
||||
std::unique_ptr<std::thread> thread;
|
||||
void send(std::string out);
|
||||
void send(Json::Value out);
|
||||
void handleMessage(std::string message);
|
||||
|
||||
Reference in New Issue
Block a user