1/* Copyright (C) 2007-2008 The Android Open Source Project
2**
3** This software is licensed under the terms of the GNU General Public
4** License version 2, as published by the Free Software Foundation, and
5** may be copied, distributed, and modified under those terms.
6**
7** This program is distributed in the hope that it will be useful,
8** but WITHOUT ANY WARRANTY; without even the implied warranty of
9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10** GNU General Public License for more details.
11*/
12#ifndef __sysdeps_h__
13#define __sysdeps_h__
14
15/* system-dependent platform abstraction used by the emulated GSM modem
16 */
17
18/* to be called before anything else */
19
20extern void  sys_main_init( void );
21
22/** callbacks
23 **/
24typedef void  (*SysCallback)( void*  opaque );
25
26/** events
27 **/
28enum {
29    SYS_EVENT_READ  = 0x01,
30    SYS_EVENT_WRITE = 0x02,
31    SYS_EVENT_ERROR = 0x04,
32    SYS_EVENT_ALL   = 0x07
33};
34
35/** channels
36 **/
37typedef struct SysChannelRec_*  SysChannel;
38
39typedef void (*SysChannelCallback)( void*  opaque, int  event_flags );
40
41/* XXX: TODO: channel creation functions */
42extern SysChannel  sys_channel_create_tcp_server( int port );
43extern SysChannel  sys_channel_create_tcp_handler( SysChannel  server_channel );
44extern SysChannel  sys_channel_create_tcp_client( const char*  hostname, int  port );
45extern int         sys_channel_set_non_block( SysChannel  channel );
46
47extern  void   sys_channel_on( SysChannel          channel,
48                               int                 event_flags,
49                               SysChannelCallback  event_callback,
50                               void*               event_opaqe );
51
52extern  int   sys_channel_read( SysChannel  channel, void*  buffer, int  size );
53
54extern  int   sys_channel_write( SysChannel  channel, const void*  buffer, int  size );
55
56extern  void  sys_channel_close( SysChannel  channel );
57
58
59/** time measurement
60 **/
61typedef long long   SysTime;
62
63extern SysTime   sys_time_now( void );
64
65/** timers
66 **/
67typedef struct SysTimerRec_*    SysTimer;
68
69extern SysTimer   sys_timer_create( void );
70extern void       sys_timer_set( SysTimer  timer, SysTime  when, SysCallback   callback, void*  opaque );
71extern void       sys_timer_unset( SysTimer  timer );
72extern void       sys_timer_destroy( SysTimer  timer );
73
74extern long long  sys_time_ms( void );
75
76/** main loop (may return immediately on some platform)
77 **/
78extern int   sys_main_loop( void );
79
80#endif /* __sysdeps_h__ */
81