
#ifndef STORE_H
#define STORE_H

#include <pthread.h>

class File;
class Server;
class Session;

class Store
{
	pthread_mutex_t mutex;
	File *spoolDir;
	int maxOpenSessions, sessionsNum, sessionsTotal;
	Session **sessions;
	Queue *queue;
	int
		fsBlockSize, reservedBlocks,
		maxSizeInKBytes, sizeInKBytes;
	dev_t imageFileDevice, spoolDirDevice;

public:
	Store();
	~Store();
	int getMaxSizeInMB() { return maxSizeInKBytes / 1024; }
	int getSizeInMB() { return sizeInKBytes / 1024; }
	int getSessionsNum() { return sessionsNum; }
	int getSessionsTotal() { return sessionsTotal; }
	File *registerSession(Session *session);
	void removeDir(const char *dirName);
	void unregister(Session *session);
	void write(const char *buf, int size, int fd);

private:
	void deleteOldestSession();
	void freeSpace();
	int getReservedBlocksForImageFile();
	int isSessionIDInUse(const char *sessionID);
	void register2(Session *session);
	void register3(Session *session);
	void removeDir2(const char *dirName);
	static void removeFile(const char *pathName);
	int sizeToBlocks(long size);
};

extern Store *store;

#endif
