1 /*******************************************************************************
2  * Copyright (c) 2014 IBM Corp.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    http://www.eclipse.org/legal/epl-v10.html
10  * and the Eclipse Distribution License is available at
11  *   http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  *    Allan Stockdill-Mander - initial API and implementation and/or initial documentation
15  *******************************************************************************/
16 
17 #if !defined(__MQTT_LINUX_)
18 #define __MQTT_LINUX_
19 
20 #if defined(WIN32_DLL) || defined(WIN64_DLL)
21   #define DLLImport __declspec(dllimport)
22   #define DLLExport __declspec(dllexport)
23 #elif defined(LINUX_SO)
24   #define DLLImport extern
25   #define DLLExport  __attribute__ ((visibility ("default")))
26 #else
27   #define DLLImport
28   #define DLLExport
29 #endif
30 
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <sys/param.h>
34 #include <sys/time.h>
35 #include <sys/select.h>
36 // #include <netinet/in.h>
37 //#include <netinet/tcp.h>
38 //#include <arpa/inet.h>
39 #include <netdb.h>
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <errno.h>
43 #include <fcntl.h>
44 
45 #include <stdlib.h>
46 #include <string.h>
47 #include <signal.h>
48 
49 typedef struct Timer
50 {
51 	struct timeval end_time;
52 } Timer;
53 
54 void TimerInit(Timer*);
55 char TimerIsExpired(Timer*);
56 void TimerCountdownMS(Timer*, unsigned int);
57 void TimerCountdown(Timer*, unsigned int);
58 int TimerLeftMS(Timer*);
59 
60 typedef struct Network
61 {
62 	int my_socket;
63 	int (*mqttread) (struct Network*, unsigned char*, int, int);
64 	int (*mqttwrite) (struct Network*, unsigned char*, int, int);
65 } Network;
66 
67 int linux_read(Network*, unsigned char*, int, int);
68 int linux_write(Network*, unsigned char*, int, int);
69 
70 DLLExport void NetworkInit(Network*);
71 DLLExport int NetworkConnect(Network*, char*, int);
72 DLLExport void NetworkDisconnect(Network*);
73 
74 #endif
75