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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/*
* ipc.h: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: ipc.h,v 1.1 2004/10/24 12:57:09 chelli-guest Exp $
*/
#ifndef __CON_IPC_H
#define __CON_IPC_H
#include <stdio.h>
#include <sys/types.h>
#include <vdr/thread.h>
// Interface that can be implemented,
// if one can wait (signal) for the object.
class IWaitable {
public:
virtual ~IWaitable() {}
virtual int SignalToWaitFor() const = 0;
};
// A List of objects we can wait for.
class cWaitableList {
private:
IWaitable** _list;
int _listCount;
fd_set _wait;
public:
cWaitableList();
~cWaitableList();
void Add( IWaitable* pObj );
void Remove( IWaitable* pObj );
bool Wait( int timeoutMs = 0 );
bool IsSignalled( IWaitable* pObj ) {
if ( pObj && pObj->SignalToWaitFor() >= 0 )
return FD_ISSET( pObj->SignalToWaitFor(), &_wait );
return false;
}
bool IsSignalled( int fd ) {
return FD_ISSET( fd, &_wait );
}
};
// This is the real pipe, but that name is taken from the vdr source.
// So I name this a simple pipe.
class cSimplePipe {
private:
int _pipe[ 2 ];
public:
cSimplePipe();
virtual ~cSimplePipe();
bool Open();
void Close();
bool IsOpen() { return _pipe[ 0 ] >= 0 && _pipe[ 1 ] >= 0; }
int getReader() const { return _pipe[ 0 ]; }
int getWriter() const { return _pipe[ 1 ]; }
};
// Can be used to signal an other thread.
// This could also be realized by using a semaphore.
// But by using a pipe one can wait for a signal with select.
class cSignal
: private cSimplePipe,
public IWaitable
{
public:
cSignal();
virtual ~cSignal() {}
void Signal();
void Reset();
bool IsSignalled();
//IWaitable
virtual int SignalToWaitFor() const { return getReader(); }
};
#endif //__CON_IPC_H
|