daemon.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. * \file daemon.h
  3. *
  4. * \brief Types and function of r.li raster analysis
  5. * server
  6. *
  7. *
  8. * \author Claudio Porta & Lucio Davide Spano
  9. *
  10. * This program is free software under the GPL (>=v2)
  11. * Read the COPYING file that comes with GRASS for details.
  12. *
  13. * \version 1.0
  14. *
  15. * \include stdlib.h
  16. *
  17. */
  18. #include <grass/gis.h>
  19. #include <grass/raster.h>
  20. #include "list.h"
  21. /**
  22. * \brief number of r.li.workers to use
  23. */
  24. #define NORMAL 1
  25. #define MVWIN 2
  26. #define GEN 3
  27. /**
  28. * \brief descriptor of a worker
  29. * \member pid worker process identifier
  30. * \member pipe name of pipe to receive message
  31. */
  32. typedef struct wd
  33. {
  34. int pid;
  35. char *pipe;
  36. int channel;
  37. } wd;
  38. /**
  39. * \brief entry of cell memory menager
  40. * \member used number of rows in cache
  41. * \member cache cache matrix
  42. * \member contents line numbers of elements in cache
  43. */
  44. struct cell_memory_entry
  45. {
  46. int used;
  47. CELL **cache;
  48. int *contents;
  49. };
  50. /**
  51. * \brief cell memory menager definition
  52. */
  53. typedef struct cell_memory_entry *cell_manager;
  54. /**
  55. * \brief entry of dcell memory menager
  56. * \member used number of rows in cache
  57. * \member cache cache matrix
  58. * \member contents line numbers of elements in cache
  59. */
  60. struct dcell_memory_entry
  61. {
  62. int used;
  63. DCELL **cache;
  64. int *contents;
  65. };
  66. /**
  67. * \brief dcell memory menager definition
  68. */
  69. typedef struct dcell_memory_entry *dcell_manager;
  70. /**
  71. * \brief entry of fcell memory menager
  72. * \member used number of rows in cache
  73. * \member cache cache matrix
  74. * \member contents line numbers of elements in cache
  75. */
  76. struct fcell_memory_entry
  77. {
  78. int used;
  79. FCELL **cache;
  80. int *contents;
  81. };
  82. /**
  83. * \brief dcell memory menager definition
  84. */
  85. typedef struct fcell_memory_entry *fcell_manager;
  86. /**
  87. * \brief fields of an area descriptor
  88. * \member x the x coordinate of upper left corner
  89. * \member y the y coordinate of upper left corner
  90. * \member rl area length in rows
  91. * \member cl area length in columns
  92. * \member mask file descriptor of mask raster file (-1 if there is no mask)
  93. */
  94. struct area_entry
  95. {
  96. int x;
  97. int y;
  98. int rl;
  99. int cl;
  100. int mask;
  101. int data_type;
  102. cell_manager cm;
  103. dcell_manager dm;
  104. fcell_manager fm;
  105. char *raster;
  106. char *mask_name;
  107. };
  108. /**
  109. * \brief applies the f index once for every
  110. * area defined in setup file
  111. * \param file name of setup file
  112. * \param f the function that defines the index
  113. * \param raster the raster file to analyze
  114. * \return 0 error occurs in calculating index
  115. * \return 1 otherwise
  116. */
  117. int calculateIndex(char *file, int f(int, char **, struct area_entry *, double *),
  118. char **parameters, char *raster, char *output);
  119. /**
  120. * \description parses the setup file and populates the list of areas
  121. * to analyze
  122. * \param setup the setup file
  123. * \param list l the list of areas to analyze
  124. * \param g areas generator for moving window analysis
  125. * \param raster raster file to analyze
  126. * \return NORMAL if the output had to be written in normal way and
  127. * list had to be used
  128. * \return GEN if the generator had to be used and the output had to
  129. * be written in normal way
  130. * \return MVWIN if a new raster file had to be created
  131. */
  132. int parseSetup(char *path, struct list *l, struct g_area *g, char *raster);
  133. /**
  134. * \description dispose sample areas if configuration file have
  135. * runtime disposition
  136. * \param l the list where to insert the areas
  137. * \param g the area generator to initialize
  138. * \param def the setup file line with the definition of disposition
  139. * \return NORMAL if the output had to be written in normal way and
  140. * list had to be used
  141. * \return GEN if the generator had to be used and the output had to
  142. * be written in normal way
  143. * \return MVWIN if a new raster file had to be created
  144. */
  145. int disposeAreas(struct list *l, struct g_area *g, char *def);
  146. /**
  147. * \brief generate the next area to analyze
  148. * \param parsed the output of a previous parseSetup function call
  149. * \param g the area generator
  150. * \param l the list of area
  151. * \param m the next message
  152. * \return 1 if the area is generated
  153. * \return 0 if there isn't another area
  154. */
  155. int next_Area(int parsed, struct list *l, struct g_area *g, msg * m);
  156. /**
  157. * \brief writes output in a file
  158. * \param out the output file
  159. * \param m the done message receive from a worker
  160. * \return 1 success
  161. * \return 0 fail
  162. */
  163. int print_Output(int out, msg m);
  164. /**
  165. * \brief writes errors in a file
  166. * \param out the output file
  167. * \param m the error message receive from a worker
  168. * \return 1 success
  169. * \return 0 fail
  170. */
  171. int error_Output(int out, msg m);
  172. /**
  173. * \brief client implementation
  174. * \param raster the raster map to analyze
  175. * \param f the function used for index computing
  176. * \param result where to put the result of index computing
  177. */
  178. void worker_init(char *raster, int f(int, char **, struct area_entry *, double *),
  179. char **parameters);
  180. void worker_process(msg * ret, msg * m);
  181. void worker_end(void);
  182. /**
  183. * \brief adapts the mask at current raster file
  184. * \param mask name of mask raster file
  185. * \param raster the name of current raster file
  186. * \param rl the lenght in rows of sample area
  187. * \param cl the lenght in cols of sample area
  188. * \return the name of mask raster file to use
  189. */
  190. char *mask_preprocessing(char *mask, char *raster, int rl, int cl);
  191. /**
  192. * \brief writes the output for a raster file
  193. * \param fd file descriptor for writing
  194. * \param aid the area identifier of result
  195. * \param res the result to be written
  196. * \return 0 on error, 1 if done
  197. */
  198. int raster_Output(int fd, int aid, struct g_area *g, double res);
  199. /**
  200. * \brief calculates a simple index for code debugging
  201. * \param fd file descriptor of raster
  202. * \param par the parameters of index not included in funtion
  203. * declaration
  204. * \param result where to return result
  205. * \return 0 on error, 1 otherwise
  206. */
  207. int simple_index(int fd, char **par, struct area_entry * ad, double *result);
  208. /**
  209. * \brief copy the content of regular file random access
  210. * on raster mv_fd
  211. * \param mv_fd the raster to write
  212. * \param random_access the regular file
  213. * \param g the mv window generator
  214. * \return 0 on error, 1 otherwise
  215. */
  216. int write_raster(int mv_fd, int random_access, struct g_area *g);
  217. /**
  218. * \brief get a cell raster row using the memory menager
  219. * \param fd file descriptor of raster to analyze
  220. * \param row identifier of row to get
  221. * \param ad area descriptor of current sample area
  222. */
  223. CELL *RLI_get_cell_raster_row(int fd, int row, struct area_entry * ad);
  224. /**
  225. * \brief get a dcell raster row using the memory menager
  226. * \param fd file descriptor of raster to analyze
  227. * \param row identifier of row to get
  228. * \param ad area descriptor of current sample area
  229. */
  230. DCELL *RLI_get_dcell_raster_row(int fd, int row, struct area_entry * ad);
  231. /**
  232. * \brief get a fcell raster row using the memory menager
  233. * \param fd file descriptor of raster to analyze
  234. * \param row identifier of row to get
  235. * \param ad area descriptor of current sample area
  236. */
  237. FCELL *RLI_get_fcell_raster_row(int fd, int row, struct area_entry * ad);
  238. #include "index.h"