Exemplo n.º 1
0
int main()
{
    Student stu = STUDENT__INIT;
    void *buf = NULL;
    unsigned int len ;
    Student *msg = NULL;

    if (malloc_student_info(&stu) == -1) {
        exit(0);
    }   
    set_student_info(&stu);

    //get student packed size
    len = student__get_packed_size(&stu);
    printf("size of student info : %u\n",len);
    buf = malloc(len);
    //put student info pack to buf
    student__pack(&stu, buf);
    
    //unpack student info from buf
    msg = student__unpack(NULL, len, buf);
    print_student_info(msg);
    //free msg
    student__free_unpacked(msg, NULL);

    free(buf);
    free_student_info(&stu);

    return 0;
}
Exemplo n.º 2
0
void * consumer_proc(void *arg)
{
    UnlockQueue* queue = (UnlockQueue *)arg;
    student_info stu_info;
    while(1)
    {
        sleep(1);
        unsigned int len = queue->Get((unsigned char *)&stu_info, sizeof(student_info));
        if(len > 0)
        {
            printf("------------------------------------------\n");
            printf("UnlockQueue length: %u\n", queue->GetDataLen());
            printf("Get a student\n");
            print_student_info(&stu_info);
            printf("------------------------------------------\n");
        }
    }
    return (void *)queue;
}