summaryrefslogtreecommitdiff
path: root/libgpsmm.cpp
blob: 80a537de99bf78e1beeef96c363a8924b5112508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (C) 2005 Alfredo Pironti
 * See the file COPYING for license conditions
 */
#include "libgpsmm.h"

struct gps_data_t* gpsmm::open(void) {
	return open("localHost",DEFAULT_GPSD_PORT);
}

struct gps_data_t* gpsmm::open(const char *host, const char *port) {
	gps_data=gps_open(host,port);
	if (gps_data==NULL) { //connection not opened
		return NULL;
	}
	else { //connection succesfully opened
		to_user= new struct gps_data_t;
		return backup(); //we return the backup of our internal structure
	}
}

struct gps_data_t* gpsmm::query(const char *request) {
	if (gps_query(gps_data,request)==-1) {
		return NULL;
	}
	else {
		return backup();
	}
}

struct gps_data_t* gpsmm::poll(void) {
	if (gps_poll(gps_data)<0) {
		// we return null if there was a read() error or connection is cloed by gpsd
		return NULL;
	}
	else {
		return backup();
	}
}

int gpsmm::set_callback(void (*hook)(struct gps_data_t *sentence, char *buf, size_t len, int level)) {
	handler = new pthread_t;
	return gps_set_callback(gps_data,hook,handler);
}

int gpsmm::del_callback(void) {
	int res;
	res=gps_del_callback(gps_data,handler);
	delete handler;
	return res;
}

void gpsmm::clear_fix(void) {
	gps_clear_fix(&(gps_data->fix));
}

gpsmm::~gpsmm() {
	if (gps_data!=NULL) {
		gps_close(gps_data);
		delete to_user;
	}
}