
#ifndef SESSION_H
#define SESSION_H

#include <stdio.h>

#include "File.h"

class Server;
class MP3toWAV;

class Session
{
	Server *server;
	const char *ID;
	File *dir, *infoFile;
	File *currentTrack;
	int currentTrackNo;
	int filesNum, tracksNum, sizeInKBytes;
	int isOpen;
	MP3toWAV *mp3towav;

public:
	Session(Server *server, const char *sessionID);
	~Session();
	const File *getFirstTrack();
	int getFilesNum() { return filesNum; }
	const char *getID() { return ID; }
	const File *getNextTrack();
	Server *getServer() { return server; }
	static int getSessionSize(File *dir);
	unsigned long getSize() { return 1024 * sizeInKBytes; }
	int getTracksNum() { return tracksNum; }
	static int isSessionDir(File &dir);
	void makeDir(const char *fileName, int mode, int time);
	void newTrack(const char *trackType);
	void open();
	void putFile(FILE *inStream,
		const char *fileName, int length, int mode, int time);
	void putTrack(FILE *inStream, int length);
private:
	void closeMP3Track();
	void copy(FILE *inStream, FILE *outStream, int length);
	void copy(const char *buf, FILE *outStream, int length);
	void copy2(FILE *inStream, FILE *outStream, int &length);
	void create();
	void countFile(const char *pathName);
	static int sizeToKBytes(int size);
};

#endif

