summaryrefslogtreecommitdiff
path: root/portland/dapi/tests/test_async.c
blob: 8828eb9b67d65896ff6390745c5d36467a537e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>

#include <dapi/comm.h>
#include <dapi/calls.h>
#include <dapi/callbacks.h>

static int seq1;

static void callback( DapiConnection* conn, int comm, int seq )
    {
    if( comm != DAPI_REPLY_BUTTONORDER
        || seq != seq1 )
        {
        fprintf( stderr, "Unexpected async reply, ignoring.\n" );
        }
    else
        {
        int ord;
        if( !dapi_readReplyButtonOrder( conn, &ord ))
            {
            fprintf( stderr, "Failed to read async reply!\n" );
            }
        else
            {
            printf( "Order async: %d (%s)\n", ord, ord == 0 ? "Failed" : ord == 1 ? "Ok/Cancel" : "Cancel/Ok" );
            }
        }
    }

int main()
    {
    int ord;
    DapiConnection* conn = dapi_connect();
    if( conn == NULL )
        {
        fprintf( stderr, "Cannot connect!\n" );
        return 1;
        }
    dapi_setGenericCallback( conn, callback );
    if( !dapi_Init( conn ))
        {
        fprintf( stderr, "Initialization failed!\n" );
        return 2;
        }
    /* first write a command request without waiting for a reply, this
       means that the following blocking dapi_ButtonOrder() call will first need to process
       an async answer */
    seq1 = dapi_writeCommandButtonOrder( conn );
    ord = dapi_ButtonOrder( conn );
    printf( "Order: %d (%s)\n", ord, ord == 0 ? "Failed" : ord == 1 ? "Ok/Cancel" : "Cancel/Ok" );
    dapi_close( conn );
    return 0;
    }