00001 /* 00002 GPS daemon manager API. The API is used by those applications that 00003 wish to use services provided by gps daemon i.e., they wish to receive 00004 GPS data from the daemon. See README file for more details. 00005 00006 Copyright (C) 2006 Nokia Corporation. All rights reserved. 00007 00008 Author: Jukka Rissanen <jukka.rissanen@nokia.com> 00009 00010 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 00011 00012 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00013 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 00014 The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 00018 */ 00019 00020 /* $Id:$ */ 00021 00022 #include <stdlib.h> 00023 #include <stdio.h> 00024 #include <sys/types.h> 00025 #include <signal.h> 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 00031 #ifndef gpsmgr_included 00032 #define gpsmgr_included 00033 00034 00035 #define GPS_TMP_DIR "/tmp/" 00036 #define GPS_CTRL_TMP_DIR "/var/run/gps/" 00037 #define GPS_CTRL_DIR "/var/lib/gps/" 00038 #define GPS_INTERNAL_DEVICE "/dev/pgps" 00039 00040 /* gpsd pid is stored to this file, also tells if the gpsd 00041 * is running or not (if not locked, then gpsd is not running) 00042 */ 00043 #define GPSMGR_GPSD_LOCK GPS_TMP_DIR ".gpsmgr_gpsd" 00044 00045 /* Lock file that manages reference count of the clients */ 00046 #define GPSMGR_LOCK GPS_TMP_DIR ".gpsmgr_lock" 00047 00048 /* Lock file that controls access to GPSMGR_LOCK file */ 00049 #define GPSMGR_LOCK2 GPS_TMP_DIR ".gpsmgr_lock2" 00050 00051 /* Status file that prevents the usage of BT GPS devices */ 00052 #define GPS_NO_BT GPS_CTRL_DIR ".gps_no_bt" 00053 00054 /* Status file that contains name(s) of BT GPS devices to be used */ 00055 #define GPS_BT_DEVICES GPS_CTRL_DIR "gps_BT_devices" 00056 00057 /* Status file that contains name(s) of serial ports of (non-BT) GPS devices */ 00058 #define GPS_SERIAL_PORTS GPS_CTRL_DIR "gps_serial_ports" 00059 00060 /* Status file that prevents the usage of serial port (non-BT) GPS devices */ 00061 #define GPS_NO_SERIAL_PORTS GPS_CTRL_DIR ".gps_no_serial_ports" 00062 00063 /* Status about connected devices */ 00064 #define GPS_CONNECTED_DEVICES GPS_CTRL_TMP_DIR "gps_connected_devices" 00065 00066 #define GPSMGR_MAX_APPLICATIONS 16 00067 #define GPSMGR_MAX_GPS_DEVICES 8 00068 00069 /* Internal context information */ 00070 typedef struct { 00071 pid_t pid; /* gpsd process pid (if we started it) */ 00072 pid_t mgr_pid; /* manager pid */ 00073 char *file; /* name of the locking file */ 00074 int lock_file_desc; /* only one lock file / application */ 00075 int locking_slot; /* what is our position in locking file, this 00076 * is used as a reference count so that we 00077 * know when there is no more clients needing 00078 * gpsd service 00079 */ 00080 00081 int already_locked_by_us; 00082 /* we already have the lock but gpsd is not yet 00083 * running (used together with 00084 * gpsmgr_is_gpsd_running() to atomically start 00085 * gpsd) 00086 */ 00087 } gpsmgr_t; 00088 00089 00095 /* Send dbus signal when gpsd is started and stopped 00096 */ 00097 #define GPSMGR_SERVICE "com.nokia.gpsmgr" 00098 #define GPSMGR_INTERFACE GPSMGR_SERVICE 00099 #define GPSMGR_PATH "/com/nokia/gpsmgr" 00100 #define GPSMGR_GPSD_STATUS_SIG "gpsd_status" 00101 00105 /* Parameter values in status signal 00106 */ 00107 #define GPSMGR_GPSD_STATUS_STARTED "started" 00108 #define GPSMGR_GPSD_STATUS_STOPPED "stopped" 00109 #define GPSMGR_GPSD_STATUS_RESTART "restart" 00110 #define GPSMGR_GPSD_STATUS_STARTED_NUM 1 00111 #define GPSMGR_GPSD_STATUS_STOPPED_NUM 2 00112 #define GPSMGR_GPSD_STATUS_RESTART_NUM 3 00113 00117 #define GPSMGR_MODE_JUST_CHECK 1 00118 #define GPSMGR_MODE_LOCK_IF_POSSIBLE (!GPSMGR_MODE_JUST_CHECK) 00119 00141 extern int gpsmgr_start(char *path, char **gps_devices, char *ctrl_sock, 00142 int debug_level, short port, gpsmgr_t *ctx); 00143 00144 00155 extern int gpsmgr_stop(gpsmgr_t *ctx); 00156 00157 00182 extern int gpsmgr_is_gpsd_running(gpsmgr_t *ctx, int *num_of_clients, int mode); 00183 00186 /* Return value defines for gpsmgr_is_gpsd_running() function. 00187 */ 00188 #define GPSMGR_NOT_RUNNING 0 00189 #define GPSMGR_RUNNING 1 00190 #define GPSMGR_READY_TO_RUN 2 00191 00203 extern int gpsmgr_set_debug_mode(int mode); 00204 00205 00213 extern int gpsmgr_request_restart(void); 00214 00217 #endif /* gpsmgr_included */ 00218 00219 #ifdef __cplusplus 00220 } 00221 #endif