summaryrefslogtreecommitdiff
path: root/src/session.hpp
blob: 9dc3f0f419ae6fe17c02ec27e23cf7cb061b1ad3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include "FileDescriptor.hpp"
#include <string>

class CSession {
  public:
	struct SRecvData {
		char	data[1024] = {0};
		ssize_t dataSize   = sizeof(data);
		bool	good	   = true;
	};
	CSession(Hyprutils::OS::CFileDescriptor m_sockfd);
	~CSession();
	std::string getName() const;
	bool		isValid() const;
	SRecvData	read();
	SRecvData	read(std::string &msg);
	bool		write(const std::string &msg) const;
	void		run();

  private:
	enum eEventType {
		READ,
		WRITE
	};
	Hyprutils::OS::CFileDescriptor m_sockfd;
	std::string					   m_name;
	void						   recvManager();
	bool						   registerSession();
	void						   onConnect() const;
	void						   onDisconnect() const;
	void						   onErrno(eEventType) const;
	void						   onRecv(SRecvData &data) const;
	friend class CSessionManager;
};