Slight reorganisation of shm member data, also blats shm on destruction.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1848 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2006-01-20 16:10:08 +00:00
parent d4e16016ba
commit 9dcdcb8508
2 changed files with 63 additions and 53 deletions

View File

@ -111,9 +111,14 @@ Monitor::~Monitor()
shared_data->state = state = IDLE;
shared_data->last_read_index = image_buffer_count;
}
else if ( purpose == CAPTURE )
{
shared_data->valid = false;
memset( shm_ptr, 0, shm_size );
}
struct shmid_ds shm_data;
if ( shmctl( shmid, IPC_STAT, &shm_data ) )
if ( shmctl( shm_id, IPC_STAT, &shm_data ) )
{
Error(( "Can't shmctl: %s", strerror(errno)));
exit( -1 );
@ -121,7 +126,7 @@ Monitor::~Monitor()
if ( shm_data.shm_nattch <= 1 )
{
if ( shmctl( shmid, IPC_RMID, 0 ) )
if ( shmctl( shm_id, IPC_RMID, 0 ) )
{
Error(( "Can't shmctl: %s", strerror(errno)));
exit( -1 );
@ -148,19 +153,19 @@ void Monitor::Setup()
Debug( 1, ( "monitor purpose=%d", purpose ));
int shared_data_size = sizeof(SharedData)
shm_size = sizeof(SharedData)
+ sizeof(TriggerData)
+ (image_buffer_count*sizeof(struct timeval))
+ (image_buffer_count*camera->ImageSize());
Debug( 1, ( "shm.size=%d", shared_data_size ));
shmid = shmget( (config.shm_key&0xffffff00)|id, shared_data_size, IPC_CREAT|0700 );
if ( shmid < 0 )
Debug( 1, ( "shm.size=%d", shm_size ));
shm_id = shmget( (config.shm_key&0xffffff00)|id, shm_size, IPC_CREAT|0700 );
if ( shm_id < 0 )
{
Error(( "Can't shmget, probably not enough shared memory space free: %s", strerror(errno)));
exit( -1 );
}
unsigned char *shm_ptr = (unsigned char *)shmat( shmid, 0, 0 );
shm_ptr = (unsigned char *)shmat( shm_id, 0, 0 );
if ( shm_ptr < 0 )
{
Error(( "Can't shmat: %s", strerror(errno)));
@ -174,7 +179,7 @@ void Monitor::Setup()
if ( purpose == CAPTURE )
{
memset( shared_data, 0, shared_data_size );
memset( shm_ptr, 0, shm_size );
shared_data->size = sizeof(SharedData);
shared_data->valid = true;
shared_data->active = enabled;

View File

@ -72,6 +72,46 @@ public:
TAPE
} State;
protected:
typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action;
typedef struct
{
int size;
bool valid;
bool active;
bool signal;
State state;
int last_write_index;
int last_read_index;
time_t last_image_time;
int last_event;
int action;
int brightness;
int hue;
int colour;
int contrast;
int alarm_x;
int alarm_y;
} SharedData;
typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState;
typedef struct
{
int size;
TriggerState trigger_state;
int trigger_score;
char trigger_cause[32];
char trigger_text[256];
char trigger_showtext[32];
} TriggerData;
typedef struct Snapshot
{
struct timeval *timestamp;
Image *image;
};
protected:
// These are read from the DB and thereafter remain unchanged
int id;
@ -119,51 +159,16 @@ protected:
time_t start_time;
time_t last_fps_time;
time_t auto_resume_time;
int shmid;
typedef struct Snapshot
{
struct timeval *timestamp;
Image *image;
};
Snapshot *image_buffer;
typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action;
typedef struct
{
int size;
bool valid;
bool active;
bool signal;
State state;
int last_write_index;
int last_read_index;
time_t last_image_time;
int last_event;
int action;
int brightness;
int hue;
int colour;
int contrast;
int alarm_x;
int alarm_y;
} SharedData;
typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState;
typedef struct
{
int size;
TriggerState trigger_state;
int trigger_score;
char trigger_cause[32];
char trigger_text[256];
char trigger_showtext[32];
} TriggerData;
int shm_id;
int shm_size;
unsigned char *shm_ptr;
SharedData *shared_data;
TriggerData *trigger_data;
Snapshot *image_buffer;
Camera *camera;
public: