예제 #1
0
THandle IpcEvent_Create(VOID)
{   
    IpcEvent_t* pIpcEvent = (IpcEvent_t*)os_MemoryCAlloc(sizeof(IpcEvent_t), sizeof(U8));
    if(pIpcEvent == NULL)
    {
        os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Create - cant allocate control block\n");
        return NULL;
    }
     
    /* create a shared memory space */
    pIpcEvent->p_shared_memory = mmap(0, sizeof(IpcEvent_Shared_Memory_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
    if ( pIpcEvent->p_shared_memory == ((PVOID)-1)) 
    {
        os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Create - cant allocate shared memory\n");
        IpcEvent_Destroy(pIpcEvent);
        return NULL;
    }

    /* create a pipe */
    pipe(pIpcEvent->p_shared_memory->pipe_fields);

    /* set the event mask to all disabled */
    pIpcEvent->p_shared_memory->event_mask = 0;

    /* Create a child process */
    pIpcEvent->child_process_id = fork();

    if (0 == pIpcEvent->child_process_id)
    {
        /******************/
        /* Child process */
        /****************/      
        IpcEvent_Child_t* pIpcEventChild = (IpcEvent_Child_t*)os_MemoryCAlloc(sizeof(IpcEvent_Child_t), sizeof(U8));        
        if(pIpcEventChild == NULL)
        {
            os_error_printf(CU_MSG_ERROR, (PS8)"ERROR - IpcEvent_Create - cant allocate child control block\n");
            _exit(1);
        }

        pIpcEventChild->p_shared_memory = pIpcEvent->p_shared_memory;

        pIpcEventChild->pipe_from_parent = pIpcEventChild->p_shared_memory->pipe_fields[PIPE_READ];
        close(pIpcEventChild->p_shared_memory->pipe_fields[PIPE_WRITE]);

        IpcEvent_Child(pIpcEventChild);

        os_MemoryFree(pIpcEventChild);

        _exit(0);
    }
 
    pIpcEvent->pipe_to_child = pIpcEvent->p_shared_memory->pipe_fields[PIPE_WRITE];
    close(pIpcEvent->p_shared_memory->pipe_fields[PIPE_READ]);
    
    return pIpcEvent;
}
예제 #2
0
VOID CuCmd_Destroy(THandle hCuCmd)
{
    CuCmd_t* pCuCmd = (CuCmd_t*)hCuCmd;

    if(pCuCmd->hCuCommon)
    {
        CuCommon_Destroy(pCuCmd->hCuCommon);
    }

    if(pCuCmd->hCuWext)
    {
        CuOs_Destroy(pCuCmd->hCuWext);
    }

    if(pCuCmd->hIpcEvent)
    {
        IpcEvent_Destroy(pCuCmd->hIpcEvent);
    }

    os_MemoryFree(pCuCmd);
}