GRASS Programmer's Manual  6.4.2(2012)
com_io.c
Go to the documentation of this file.
00001 
00002 #include <grass/config.h>
00003 
00004 #include <errno.h>
00005 #include <signal.h>
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include <unistd.h>
00010 
00011 #include <grass/gis.h>
00012 #include <grass/glocale.h>
00013 #include <grass/raster.h>
00014 #include <grass/graphics.h>
00015 
00016 #include "driver.h"
00017 #include "transport.h"
00018 
00019 struct transport loc_trans = {
00020     LOC_open_driver,
00021     LOC__open_quiet,
00022     LOC_stabilize,
00023     LOC_kill_driver,
00024     LOC_close_driver,
00025     LOC_release_driver,
00026     LOC_screen_left,
00027     LOC_screen_rite,
00028     LOC_screen_bot,
00029     LOC_screen_top,
00030     LOC_get_num_colors,
00031     LOC_standard_color,
00032     LOC_RGB_color,
00033     LOC_line_width,
00034     LOC_erase,
00035     LOC_move_abs,
00036     LOC_move_rel,
00037     LOC_cont_abs,
00038     LOC_cont_rel,
00039     LOC_polydots_abs,
00040     LOC_polydots_rel,
00041     LOC_polyline_abs,
00042     LOC_polyline_rel,
00043     LOC_polygon_abs,
00044     LOC_polygon_rel,
00045     LOC_box_abs,
00046     LOC_box_rel,
00047     LOC_text_size,
00048     LOC_text_rotation,
00049     LOC_set_window,
00050     LOC_text,
00051     LOC_get_text_box,
00052     LOC_font,
00053     LOC_charset,
00054     LOC_font_list,
00055     LOC_font_info,
00056     LOC_panel_save,
00057     LOC_panel_restore,
00058     LOC_panel_delete,
00059     LOC_begin_scaled_raster,
00060     LOC_scaled_raster,
00061     LOC_end_scaled_raster,
00062     LOC_bitmap,
00063     LOC_get_location_with_box,
00064     LOC_get_location_with_line,
00065     LOC_get_location_with_pointer,
00066     LOC_pad_create,
00067     LOC_pad_current,
00068     LOC_pad_delete,
00069     LOC_pad_invent,
00070     LOC_pad_list,
00071     LOC_pad_select,
00072     LOC_pad_append_item,
00073     LOC_pad_delete_item,
00074     LOC_pad_get_item,
00075     LOC_pad_list_items,
00076     LOC_pad_set_item
00077 };
00078 
00079 #ifdef HAVE_SOCKET
00080 
00081 struct transport rem_trans = {
00082     REM_open_driver,
00083     REM__open_quiet,
00084     REM_stabilize,
00085     REM_kill_driver,
00086     REM_close_driver,
00087     REM_release_driver,
00088     REM_screen_left,
00089     REM_screen_rite,
00090     REM_screen_bot,
00091     REM_screen_top,
00092     REM_get_num_colors,
00093     REM_standard_color,
00094     REM_RGB_color,
00095     REM_line_width,
00096     REM_erase,
00097     REM_move_abs,
00098     REM_move_rel,
00099     REM_cont_abs,
00100     REM_cont_rel,
00101     REM_polydots_abs,
00102     REM_polydots_rel,
00103     REM_polyline_abs,
00104     REM_polyline_rel,
00105     REM_polygon_abs,
00106     REM_polygon_rel,
00107     REM_box_abs,
00108     REM_box_rel,
00109     REM_text_size,
00110     REM_text_rotation,
00111     REM_set_window,
00112     REM_text,
00113     REM_get_text_box,
00114     REM_font,
00115     REM_charset,
00116     REM_font_list,
00117     REM_font_info,
00118     REM_panel_save,
00119     REM_panel_restore,
00120     REM_panel_delete,
00121     REM_begin_scaled_raster,
00122     REM_scaled_raster,
00123     REM_end_scaled_raster,
00124     REM_bitmap,
00125     REM_get_location_with_box,
00126     REM_get_location_with_line,
00127     REM_get_location_with_pointer,
00128     REM_pad_create,
00129     REM_pad_current,
00130     REM_pad_delete,
00131     REM_pad_invent,
00132     REM_pad_list,
00133     REM_pad_select,
00134     REM_pad_append_item,
00135     REM_pad_delete_item,
00136     REM_pad_get_item,
00137     REM_pad_list_items,
00138     REM_pad_set_item
00139 };
00140 
00141 #endif
00142 
00143 const struct transport *trans;
00144 
00145 static const struct transport *get_trans(void)
00146 {
00147 #ifndef HAVE_SOCKET
00148     return &loc_trans;
00149 #else
00150     const char *p = getenv("GRASS_RENDER_IMMEDIATE");
00151 
00152     if (!p)
00153         return &rem_trans;
00154 
00155     if (G_strcasecmp(p, "TRUE") == 0)
00156         return &loc_trans;
00157 
00158     if (G_strcasecmp(p, "FALSE") == 0)
00159         return &rem_trans;
00160 
00161     if (G_strcasecmp(p, "PNG") == 0)
00162         return &loc_trans;
00163 
00164     if (G_strcasecmp(p, "PS") == 0)
00165         return &loc_trans;
00166 
00167     G_warning("Unrecognised GRASS_RENDER_IMMEDIATE setting: %s", p);
00168 
00169     return &rem_trans;
00170 #endif
00171 }
00172 
00173 static void init_transport(void)
00174 {
00175     if (trans)
00176         return;
00177 
00178     trans = get_trans();
00179 }
00180 
00181 int R_open_driver(void)
00182 {
00183     init_transport();
00184     return trans->open_driver();
00185 }
00186 
00187 void R__open_quiet(void)
00188 {
00189     init_transport();
00190     trans->open_quiet();
00191 }
00192 
00193 void R_stabilize(void)
00194 {
00195     trans->stabilize();
00196 }
00197 
00198 void R_kill_driver(void)
00199 {
00200     trans->kill_driver();
00201 }
00202 
00203 void R_close_driver(void)
00204 {
00205     trans->close_driver();
00206 }
00207 
00208 void R_release_driver(void)
00209 {
00210     trans->release_driver();
00211 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines