cleanup specfile for packaging
[profile/ivi/gpsd.git] / libgpsmm.cpp
1 /*
2  * Copyright (C) 2005 Alfredo Pironti
3  *
4  * This software is distributed under a BSD-style license. See the
5  * file "COPYING" in the top-level directory of the disribution for details.
6  *
7  */
8 #include <cstdlib>
9
10 #include "gpsd_config.h"
11 #include "libgpsmm.h"
12
13 gpsmm::gpsmm() : gps_data(0) { gps_data = NULL; }
14
15 struct gps_data_t* gpsmm::open(void) {
16         return open("localhost",DEFAULT_GPSD_PORT);
17 }
18
19 struct gps_data_t* gpsmm::open(const char *host, const char *port) {
20         gps_data=gps_open(host,port);
21         if (gps_data==NULL) { //connection not opened
22                 return NULL;
23         }
24         else { //connection succesfully opened
25                 to_user= new struct gps_data_t;
26                 return backup(); //we return the backup of our internal structure
27         }
28 }
29
30 struct gps_data_t* gpsmm::stream(int flags) {
31   if (gps_stream(gps_data,flags, NULL)==-1) {
32                 return NULL;
33         }
34         else {
35                 return backup();
36         }
37 }
38
39 struct gps_data_t* gpsmm::send(const char *request) {
40         if (gps_send(gps_data,request)==-1) {
41                 return NULL;
42         }
43         else {
44                 return backup();
45         }
46 }
47
48 struct gps_data_t* gpsmm::poll(void) {
49         if (gps_poll(gps_data)<0) {
50                 // we return null if there was a read() error or connection is cloed by gpsd
51                 return NULL;
52         }
53         else {
54                 return backup();
55         }
56 }
57
58 int gpsmm::close(void) {
59         return gps_close(gps_data);
60 }
61
62 bool gpsmm::waiting(void) {
63         return gps_waiting(gps_data);
64 }
65
66 void gpsmm::clear_fix(void) {
67         gps_clear_fix(&(gps_data->fix));
68 }
69
70 void gpsmm::enable_debug(int level, FILE *fp) {
71 #ifdef CLIENTDEBUG_ENABLE
72         gps_enable_debug(level, fp);
73 #endif /* CLIENTDEBUG_ENABLE */
74 }
75
76 gpsmm::~gpsmm() {
77         if (gps_data!=NULL) {
78                 gps_close(gps_data);
79                 delete to_user;
80         }
81 }