00001 #ifndef _ShmInit_CC_
00002 #define _ShmInit_CC_
00003
00004 #include "../includes/Header.hh"
00005 #include "../ShmCommon.h"
00006 using namespace std;
00007
00008 int ShmInit(key_t shm_key, int shm_size,int *shrd_id,int *shm_ptr)
00009 {
00010 shm_key = ftok(KEYFILE_PATH,PROJ_CHAR);
00011 if( shm_key == -1 ) {
00012 perror("ftok()");
00013 return 1;
00014 }
00015 *shrd_id = shmget(shm_key, shm_size, IPC_CREAT|0666);
00016 if( *shrd_id < 0 ){
00017 printf("[shm_initialize]: Can't Access to the Shared Memory !! \n" );
00018 return -1;
00019 }
00020 *shm_ptr = (int)shmat( *shrd_id, NULL, 0);
00021 memset( (void *)*shm_ptr, 0, shm_size );
00022
00023 return *shrd_id;
00024 }
00025
00026 #endif