1 /* Copyright (c) 2011, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef LOC_API_CB_SYNC_H
30 #define LOC_API_CB_SYNC_H
31 
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36 #include "loc_api_rpc_glue.h"
37 #define LOC_SYNC_CALL_SLOTS_MAX 8
38 
39 typedef struct {
40    pthread_mutex_t                lock;
41 
42    /* Client ID */
43    rpc_loc_client_handle_type     loc_handle;
44 
45    /* Callback waiting conditional variable */
46    pthread_cond_t                 loc_cb_arrived_cond;
47 
48    /* Callback waiting data block, protected by loc_cb_data_mutex */
49    boolean                        in_use;
50    boolean                        signal_sent;
51    boolean                        not_available;
52    rpc_loc_event_mask_type        loc_cb_wait_event_mask;        /* event to wait for */
53    rpc_loc_ioctl_e_type           ioctl_type;                    /* ioctl to wait for */
54    rpc_loc_event_payload_u_type   loc_cb_received_payload;       /* received payload */
55    rpc_loc_event_mask_type        loc_cb_received_event_mask;    /* received event   */
56 } loc_sync_call_slot_s_type;
57 
58 typedef struct {
59    int                            num_of_slots;
60    loc_sync_call_slot_s_type      slots[LOC_SYNC_CALL_SLOTS_MAX];
61 } loc_sync_call_slot_array_s_type;
62 
63 /* Init function */
64 void loc_api_sync_call_init();
65 
66 /* Destroy function */
67 void loc_api_sync_call_destroy();
68 
69 /* Process Loc API callbacks to wake up blocked user threads */
70 void loc_api_callback_process_sync_call(
71       rpc_loc_client_handle_type            loc_handle,             /* handle of the client */
72       rpc_loc_event_mask_type               loc_event,              /* event mask           */
73       const rpc_loc_event_payload_u_type*   loc_event_payload       /* payload              */
74 );
75 
76 /* Reentrant synchronous IOCTL call, using Loc API return code */
77 int loc_api_sync_ioctl
78 (
79       rpc_loc_client_handle_type           handle,
80       rpc_loc_ioctl_e_type                 ioctl_type,
81       rpc_loc_ioctl_data_u_type*           ioctl_data_ptr,
82       uint32                               timeout_msec,
83       rpc_loc_ioctl_callback_s_type       *cb_data_ptr
84 );
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* LOC_API_CB_SYNC_H */
91