GTA04: Added device files with working transport handlers
[hayes-ril.git] / hayes-ril.h
1 /**
2  * This file is part of hayes-ril.
3  *
4  * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
5  * 
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef _HAYES_RIL_H_
20 #define _HAYES_RIL_H_
21
22 #define RIL_DEVICE_LOCK(ril_device_p) pthread_mutex_lock(&(ril_device_p->handlers->transport->mutex));
23 #define RIL_DEVICE_UNLOCK(ril_device_p) pthread_mutex_unlock(&(ril_device_p->handlers->transport->mutex));
24
25 #define DEV_GSM         RIL_DEVICE_TYPE_GSM
26 #define DEV_CDMA        RIL_DEVICE_TYPE_CDMA
27
28 extern struct ril_device *ril_device;
29
30 enum ril_device_type {
31         RIL_DEVICE_TYPE_GSM,
32         RIL_DEVICE_TYPE_CDMA
33 };
34
35 struct ril_device_power_handlers {
36         void *sdata;
37         int (*sdata_create)(void **sdata);
38         int (*sdata_destroy)(void *sdata);
39
40         int (*power_on)(void *sdata);
41         int (*power_off)(void *sdata);
42
43         int (*suspend)(void *sdata);
44         int (*resume)(void *sdata);
45
46         int (*boot)(void *sdata);
47 };
48
49 struct ril_device_transport_handlers {
50         void *sdata;
51         int (*sdata_create)(void **sdata);
52         int (*sdata_destroy)(void *sdata);
53
54         int (*open)(void *sdata);
55         int (*close)(void *sdata);
56
57         int (*send)(void *sdata, void **data, int length);
58         int (*recv)(void *sdata, void **data, int length);
59
60         int (*recv_poll)(void *sdata);
61
62         pthread_t recv_thread;
63         pthread_mutex_t mutex;
64 };
65
66 struct ril_device_handlers {
67         struct ril_device_power_handlers *power;
68         struct ril_device_transport_handlers *transport;
69 };
70
71 struct ril_device {
72         char *name;
73         void *sdata;
74
75         enum ril_device_type type;
76         struct ril_device_handlers *handlers;
77 };
78
79 // Device
80 void ril_device_register(struct ril_device **ril_device_p);
81 int ril_device_init(struct ril_device *ril_device_p);
82 int ril_device_deinit(struct ril_device *ril_device_p);
83
84 int ril_device_data_create(struct ril_device *ril_device_p);
85 int ril_device_data_destroy(struct ril_device *ril_device_p);
86 int ril_device_boot(struct ril_device *ril_device_p);
87 int ril_device_boot(struct ril_device *ril_device_p);
88 int ril_device_power_on(struct ril_device *ril_device_p);
89 int ril_device_power_off(struct ril_device *ril_device_p);
90 int ril_device_open(struct ril_device *ril_device_p);
91 int ril_device_close(struct ril_device *ril_device_p);
92 int ril_device_send(struct ril_device *ril_device_p, void *data, int length);
93 int ril_device_recv(struct ril_device *ril_device_p, void **data, int length);
94 int ril_device_recv_poll(struct ril_device *ril_device_p);
95 int ril_device_recv_thread_start(struct ril_device *ril_device_p);
96
97 #endif