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 /* User selected device (written by location applet) */ 00067 #define GPS_USER_SELECTED GPS_CTRL_DIR "gps_user_selected" 00068 00069 00070 #define GPSMGR_MAX_APPLICATIONS 16 00071 #define GPSMGR_MAX_GPS_DEVICES 8 00072 00073 /* Internal context information */ 00074 typedef struct { 00075 pid_t pid; /* gpsd process pid (if we started it) */ 00076 pid_t mgr_pid; /* manager pid */ 00077 char *file; /* name of the locking file */ 00078 int lock_file_desc; /* only one lock file / application */ 00079 int locking_slot; /* what is our position in locking file, this 00080 * is used as a reference count so that we 00081 * know when there is no more clients needing 00082 * gpsd service 00083 */ 00084 00085 int already_locked_by_us; 00086 /* we already have the lock but gpsd is not yet 00087 * running (used together with 00088 * gpsmgr_is_gpsd_running() to atomically start 00089 * gpsd) 00090 */ 00091 } gpsmgr_t; 00092 00093 00099 /* Send dbus signal when gpsd is started and stopped 00100 */ 00101 #define GPSMGR_SERVICE "com.nokia.gpsmgr" 00102 #define GPSMGR_INTERFACE GPSMGR_SERVICE 00103 #define GPSMGR_PATH "/com/nokia/gpsmgr" 00104 #define GPSMGR_GPSD_STATUS_SIG "gpsd_status" 00105 00109 /* Parameter values in status signal 00110 */ 00111 #define GPSMGR_GPSD_STATUS_STARTED "started" 00112 #define GPSMGR_GPSD_STATUS_STOPPED "stopped" 00113 #define GPSMGR_GPSD_STATUS_RESTART "restart" 00114 #define GPSMGR_GPSD_STATUS_STARTED_NUM 1 00115 #define GPSMGR_GPSD_STATUS_STOPPED_NUM 2 00116 #define GPSMGR_GPSD_STATUS_RESTART_NUM 3 00117 00121 #define GPSMGR_MODE_JUST_CHECK 1 00122 #define GPSMGR_MODE_LOCK_IF_POSSIBLE (!GPSMGR_MODE_JUST_CHECK) 00123 00145 extern int gpsmgr_start(char *path, char **gps_devices, char *ctrl_sock, 00146 int debug_level, short port, gpsmgr_t *ctx); 00147 00148 00159 extern int gpsmgr_stop(gpsmgr_t *ctx); 00160 00161 00186 extern int gpsmgr_is_gpsd_running(gpsmgr_t *ctx, int *num_of_clients, int mode); 00187 00190 /* Return value defines for gpsmgr_is_gpsd_running() function. 00191 */ 00192 #define GPSMGR_NOT_RUNNING 0 00193 #define GPSMGR_RUNNING 1 00194 #define GPSMGR_READY_TO_RUN 2 00195 00207 extern int gpsmgr_set_debug_mode(int mode); 00208 00209 00217 extern int gpsmgr_request_restart(void); 00218 00221 #endif /* gpsmgr_included */ 00222 00223 #ifdef __cplusplus 00224 } 00225 #endif