pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_c_edges.c
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: testXYedges.c
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2015 Rohith Reddy
10 Mail:
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28 ********************************************************************PGR-GNU*/
29 
30 #include "postgres.h"
31 #include "executor/spi.h"
32 #include "funcapi.h"
33 #include "utils/array.h"
34 #include "catalog/pg_type.h"
35 #if PGSQL_VERSION > 92
36 #include "access/htup_details.h"
37 #endif
38 #include "fmgr.h"
39 
40 #include "./../../common/src/debug_macro.h"
41 #include "./../../common/src/pgr_types.h"
42 #include "./../../common/src/postgres_connection.h"
43 #include "./../../common/src/edges_input.h"
44 
45 #include "./test_c_edges_driver.h"
46 
47 PGDLLEXPORT Datum test_c_edges(PG_FUNCTION_ARGS);
48 
49 
50 static
51 void
52 process(char *edges_sql,
53  bool *result_bool) {
55 
56  PGR_DBG("Load data");
57  pgr_edge_t *edges = NULL;
58  size_t total_edges = 0;
59  pgr_get_edges(edges_sql, &edges, &total_edges);
60 
61  if (total_edges == 0) {
62  PGR_DBG("No edges found");
63  (*result_bool) = true;
64  pfree(edges);
66  return;
67  }
68  PGR_DBG("Total %ld tuples in query:", total_edges);
69  size_t i;
70  for (i = 0; i < total_edges; ++i) {
71  PGR_DBG("id = %li \t source = %li \t target = %ld cost = %lf reverse_cost = %lf",
72  edges[i].id, edges[i].source, edges[i].target, edges[i].cost, edges[i].reverse_cost);
73  /*PGR_DBG(" (x1,y1) = (%.32lf ,%.32lf) (x2,y2) = (%.32lf,.%.32lf)",
74  edges[i].x1, edges[i].y1, edges[i].x2, edges[i].y2);*/
75  }
76 
77 
78  PGR_DBG("Starting processing");
79  char *err_msg = NULL;
80  char *log_msg = NULL;
81  (*result_bool) = do_pgr_test_c_edges(
82  edges,
83  total_edges,
84  &log_msg,
85  &err_msg);
86 
87  pfree(edges);
88  elog(NOTICE, "Returned log message = %s\n", log_msg);
89  if (log_msg) {
90  elog(DEBUG1, "%s", log_msg);
91  free(log_msg);
92  }
93  PGR_DBG("Returned error message = %s\n", err_msg);
94 
95  if (err_msg) {
96  elog(ERROR, "%s", err_msg);
97  free(err_msg);
98  }
99 
100  pgr_SPI_finish();
101 }
102 
104 PGDLLEXPORT Datum
105 test_c_edges(PG_FUNCTION_ARGS) {
106  bool result_bool = false;
107  process(
108  pgr_text2char(PG_GETARG_TEXT_P(0)),
109  &result_bool);
110 
111  PG_RETURN_BOOL(result_bool);
112 }
113 
PGDLLEXPORT Datum test_c_edges(PG_FUNCTION_ARGS)
Definition: test_c_edges.c:105
PG_FUNCTION_INFO_V1(test_c_edges)
#define PGR_DBG(...)
Definition: debug_macro.h:33
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:535
bool do_pgr_test_c_edges(pgr_edge_t *data_edges, size_t total_edges, char **log_msg, char **err_msg)
void pgr_SPI_finish(void)
edge_astar_t * edges
Definition: BDATester.cpp:46
void pgr_SPI_connect(void)
char * err_msg
Definition: BDATester.cpp:50
static void process(char *edges_sql, bool *result_bool)
Definition: test_c_edges.c:52
char * pgr_text2char(text *in)