]> Pileus Git - grits/blob - src/wms.h
Reorganize BMNG and SRTM into plugins
[grits] / src / wms.h
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __WMS_H__
19 #define __WMS_H__
20
21 #include <math.h>
22 #include <time.h>
23 #include <libsoup/soup.h>
24
25 typedef struct _WmsCacheNode WmsCacheNode;
26 typedef struct _WmsInfo WmsInfo;
27
28 typedef void (*WmsChunkCallback)(gsize cur, gsize total, gpointer user_data);
29 typedef void (*WmsDoneCallback)(WmsCacheNode *node, gpointer user_data);
30 typedef void (*WmsLoader)(WmsCacheNode *node, const gchar *path, gint width, gint height);
31 typedef void (*WmsFreeer)(WmsCacheNode *node);
32
33 /****************
34  * WmsCacheNode *
35  ****************/
36 struct _WmsCacheNode {
37         gpointer data;
38         gdouble  latlon[4]; // xmin,ymin,xmax,ymax
39         gdouble  res;       // xmin,ymin,xmax,ymax
40         gboolean caching;
41         time_t   atime;
42         WmsCacheNode *parent;
43         WmsCacheNode *children[4][4];
44 };
45
46 WmsCacheNode *wms_cache_node_new(WmsCacheNode *parent, gdouble xmin, gdouble ymin, gdouble xmax, gdouble ymax, gint width);
47
48 void wms_cache_node_free(WmsCacheNode *node, WmsFreeer freeer);
49
50 /***********
51  * WmsInfo *
52  ***********/
53 struct _WmsInfo {
54         gchar *uri_prefix;
55         gchar *uri_layer;
56         gchar *uri_format;
57         gchar *cache_prefix;
58         gchar *cache_ext;
59         gint   resolution;  // m/px
60         gint   width;
61         gint   height;
62
63         guint  max_age;
64         guint  gc_source;
65         time_t atime;
66         WmsLoader     loader;
67         WmsFreeer     freeer;
68         WmsCacheNode *cache_root;
69         SoupSession  *soup;
70 };
71
72 WmsInfo *wms_info_new(WmsLoader loader, WmsFreeer freeer,
73                 gchar *uri_prefix, gchar *uri_layer, gchar *uri_format,
74                 gchar *cache_prefix, gchar *cache_ext,
75                 gint   resolution, gint   width, gint   height);
76
77 void wms_info_cache(WmsInfo *info, gdouble resolution, gdouble lat, gdouble lon,
78                 WmsChunkCallback chunk_callback, WmsDoneCallback done_callback,
79                 gpointer user_data);
80
81 WmsCacheNode *wms_info_fetch(WmsInfo *info, WmsCacheNode *root,
82                 gdouble resolution, gdouble lat, gdouble lon,
83                 gboolean *correct);
84
85 WmsCacheNode *wms_info_fetch_cache(WmsInfo *info, WmsCacheNode *root,
86                 gdouble resolution, gdouble lat, gdouble lon,
87                 WmsChunkCallback chunk_callback, WmsDoneCallback done_callback,
88                 gpointer user_data);
89
90 gboolean wms_info_gc(WmsInfo *self);
91
92 void wms_info_free(WmsInfo *info);
93
94
95 /********************************
96  * Specific things (bmng, srtm) *
97  ********************************/
98 typedef struct _WmsBil WmsBil;
99 struct _WmsBil {
100         gint16 *data;
101         gint width;
102         gint height;
103 };
104
105 void bmng_opengl_loader(WmsCacheNode *node, const gchar *path, gint width, gint height);
106 void bmng_opengl_freeer(WmsCacheNode *node);
107
108 void bmng_pixbuf_loader(WmsCacheNode *node, const gchar *path, gint width, gint height);
109 void bmng_pixbuf_freeer(WmsCacheNode *node);
110
111 WmsInfo *wms_info_new_for_bmng(WmsLoader loader, WmsFreeer freeer);
112
113 void srtm_bil_loader(WmsCacheNode *node, const gchar *path, gint width, gint height);
114 void srtm_bil_freeer(WmsCacheNode *node);
115
116 void srtm_pixbuf_loader(WmsCacheNode *node, const gchar *path, gint width, gint height);
117 void srtm_pixbuf_freeer(WmsCacheNode *node);
118
119 WmsInfo *wms_info_new_for_srtm(WmsLoader loader, WmsFreeer freeer);
120
121 #endif