コード例 #1
0
/*
 *  ======== Comm_create ========
 */
Comm_Handle Comm_create(String queueName, Comm_Attrs *attrs)
{
    Comm_Obj   *comm;
    UInt32      commId;
    Char        commName[ MAXCOMMNAMELEN ];
    key_t       key;

    Assert_isTrue(curInit > 0, (Assert_Id)NULL);

    Log_print2(Diags_ENTRY, "[+E] Comm_create> "
            "Enter(queueName='%s', attrs=0x%x)", (IArg)queueName, (IArg)attrs);

    if (attrs == NULL) {
        attrs = &Comm_ATTRS;
    }

    if (queueName == NULL) {
        /* Generate a name to use */
        // TODO: Increment curCommId atomically
        commId = curCommId++;
        sprintf(commName, "queue_%lu_%u", Global_getProcessId(), (Uns)commId);
        key = nameToId(commName);
    }
    else {
        key = nameToId(queueName);
    }

    comm = (Comm_Obj *)Memory_alloc(NULL, sizeof(Comm_Obj), 0, NULL);
    if (comm == NULL) {
        return (NULL);
    }

    comm->type = attrs->type;

    if (comm->type == Comm_PEND) {
        ;
    }
    else if (comm->type == Comm_CALL) {
        comm->callHandle = attrs->callHandle;
        comm->callFxn    = attrs->callFxn;
    }
    else {
        Assert_isTrue(FALSE, (Assert_Id)NULL);  /* unknown Comm type */
    }

    /*
     * Create a new message queue id for the "name" key
     */
    if ((comm->id = msgget(key, IPC_CREAT | 0644)) < 0) {
        fprintf(stderr, "msgget key = 0x%x\n", key);
        perror("Comm_create:msgget");
        Memory_free(NULL, comm, sizeof(Comm_Obj));
        return (NULL);
    }

    Log_print1(Diags_EXIT, "[+X] Comm_create> return (0x%x)", (IArg)comm);

    return (comm);
}
コード例 #2
0
ファイル: ladclient_wince.c プロジェクト: sv99/DVSDK
/*
 *  ======== LAD_connect ========
 */
LAD_Status LAD_connect(LAD_ClientHandle * handle)
{
    LAD_Status  status = LAD_SUCCESS;
    Int         clientId;
    UInt32      pid;

//    DebugBreak();

    /* sanity check arg */
    if (handle == NULL) {
        return (LAD_INVALIDARG);
    }

    /* check and initialize on first connect request */
    if (refCount++ == 0) {

        /* TODO:M does this need to be atomized? */
        status = initLad();
        if (status != LAD_SUCCESS) {
            return (status);
        }
    }

    /* get caller's process ID */
    // TODO: Do we need a unique ID? For kernel drivers at startup, the
    // Process Id is the same.
    pid = Global_getProcessId();

    clientId = assignClientId();

    if (clientId == -1) {
        PRINTVERBOSE0("\nLAD_connect failed: To many connections!\n");
        *handle = (LAD_ClientHandle)-1;
        status = LAD_ACCESSDENIED;
    }
    else {
        /* setup client info */
        clientInfo[clientId].PID = pid;
        clientInfo[clientId].connectedToLAD = TRUE;
        *handle = (LAD_ClientHandle)clientId;
    }

    return (status);
}