File: gpsdwizard.fl

package info (click to toggle)
obdgpslogger 0.16-1.3
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 5,160 kB
  • ctags: 7,498
  • sloc: ansic: 73,206; cpp: 2,055; php: 407; sh: 51; makefile: 4
file content (179 lines) | stat: -rw-r--r-- 3,791 bytes parent folder | download | duplicates (2)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# data file for the Fltk User Interface Designer (fluid)
version 1.0109 
header_name {.h} 
code_name {.cxx}
decl {\#include <sys/types.h>} {public
} 

decl {\#include <signal.h>} {public
} 

decl {\#include <sys/wait.h>} {} 

decl {\#include <unistd.h>} {} 

decl {\#include <FL/Fl_File_Chooser.H>} {} 

decl {\#include "guessdevs.h"} {} 

decl {\#include "obdconfig.h"} {public
} 

decl {\#include "obdgui.h"} {public
} 

class GPSDWizardWindow {open
} {
  Function {GPSDWizardWindow()} {open
  } {
    Fl_Window window {
      label {GPSD Launch Wizard} open
      private xywh {1190 75 455 145} type Double align 80
      code1 {// o->hide();} visible
    } {
      Fl_Group {} {
        label {GPSD Options} open
        xywh {10 25 435 75} box BORDER_BOX
      } {
        Fl_Group devchooser_group {open
          xywh {100 33 345 67}
        } {
          Fl_Button devchooser {
            label {Choose...}
            callback {Fl_File_Chooser f("",
  "All Files (*)",
  Fl_File_Chooser::SINGLE, "GPS Device" );
f.show();
while(f.shown()) {
  Fl::check();
}
if(0 < f.count())
  gpsd_devicename->value(f.value());}
            private xywh {360 35 80 25}
          }
          Fl_Input_Choice gpsd_devicename {
            label {GPSD Device} open
            xywh {115 33 225 28}
          } {}
        }
        Fl_Check_Button broken_device_safety {
          label {Safe Mode}
          private xywh {265 70 90 25} down_box DOWN_BOX
          code0 {o->set();}
        }
      }
      Fl_Button launchbutton {
        label {Launch GPSD}
        callback {launch_gpsd();}
        private xywh {30 110 130 25}
      }
      Fl_Button killbutton {
        label {Kill GPSD}
        callback {kill_gpsd();}
        private xywh {185 110 130 25}
      }
      Fl_Button closebutton {
        label Close
        callback {window->hide();}
        private xywh {360 110 70 20}
      }
    }
    code {populateSerialDevs(gpsd_devicename, OBD_DEFAULT_GPSPORT);} {selected
    }
  }
  Function {launch_gpsd()} {open private return_type int
  } {
    code {int safemode = broken_device_safety->value();
const char *devname = gpsd_devicename->value();

// printf("PATH: %s\\n", getenv("PATH"));
int pid = fork();

if(pid > 0) {  // Parent
	sleep(2);
	gpsd_add_device(gpsd_devicename->value());
	return 0;
}

if(pid == 0) { // Child
	execlp("gpsd",
		"gpsd",
		"-F",
		OBD_GPSD_CONTROL_SOCKET,
		"-P",
		OBD_GPSD_PIDFILE,
		// This pattern won't work if we get more options
		safemode?"-b":NULL,
		NULL);
	perror("Exec failed");
	exit(1);
}

perror("Couldn't fork to launch gpsd...\\n");

return -1;} {}
  }
  Function {kill_gpsd()} {open private
  } {
    code {pid_t p = getGpsdPid();

if(0 >= p) return;

if(0 > kill(p,SIGTERM)) {
	perror("Couldn't SIGTERM gpsd");
} else {
	sleep(1); // Give it a second to get itself dead
	if(0 < waitpid(p, NULL, WNOHANG)) {
		if(0 != kill(p,SIGKILL)) {
			perror("Couldn't SIGKILL gpsd");
		}
	}
}} {}
  }
  Function {show()} {open return_type void
  } {
    code {window->show();} {}
  }
  Function {hide()} {open return_type void
  } {
    code {window->hide();} {}
  }
  Function {getGpsdPid()} {open return_type pid_t
  } {
    code {FILE *pidfile = fopen(OBD_GPSD_PIDFILE, "r");

if(NULL == pidfile) return -1;

long pid;
if(1 == fscanf(pidfile, "%li", &pid)) {
	fclose(pidfile);
	return pid;
}

fclose(pidfile);
return -1;} {}
  }
  Function {gpsd_add_device(const char *devname)} {open return_type void
  } {
    code {if(0 >= getGpsdPid()) {
	return;
}

if(NULL == devname || 0 == strlen(devname)) {
	return;
}

FILE *control = fopen(OBD_GPSD_CONTROL_SOCKET, "w");
if(NULL == control) {
	return;
}

fprintf(control, "+%s\\n", devname);

fclose(control);} {}
  }
  Function {~GPSDWizardWindow()} {open
  } {
    code {kill_gpsd();} {}
  }
}