The Open Source Swiss Army Knife

/miscellany/
/miscellany/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /miscellany 
Permalink: /var/sirfsup/miscellany/ipc.h
Title: add
article options : please login   |  raw source view  

#ifndef __IPC_H_
#define __IPC_H_

// is a linked list type class which 
// stores session objects
// which is stored in shared memory
// which is protected by a semaphore
// oh my

#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>

#include <iostream>

#define FKEY "/tmp/session"
#define ALLSIZE (sizeof(int)+sizeof(session)*MAXSESSIONS)

#define PROJ 57
#define SIDSIZE 9 /* nineth byte is for 0 */
#define EXPIRE  600 /* seconds */
#define MAXSESSIONS 512


#include "session_node.h"
#include "session.h"
#include "sessionList.h"

class sessionIPC : public sessionList {

friend std::ostream & operator<<(std::ostream & , sessionIPC &);

private:
	// variables
	int shmid,semid;
	key_t key;
	int numsessions;
	node * first;
	struct sembuf buf;

	// methods
	int getSemID(key_t key);
	int getShmID(key_t key);
	int lockSession(int semid);
	int unlockSession(int semid);
public:
	// virtual
	sessionIPC();
	~sessionIPC(); // virtual by inheritance
	// START virtual functions
	bool getSession(session &, const string &);
	bool findSession(const string &);
	bool addSession(session &);
	bool removeSessions(); // deletes all sessions
	bool removeSession(session &);
	void cleanUp(); // remove time-expired sessions
	string get_id_from_key(const string, const string);// 1-key,2-value, return: _id
	// end virtual functions
	node * getFirst() { return first; }
	// non-virtual
	bool destroy(); // remove the shared memory
};


#endif

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top