GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
ret_codes.c
Go to the documentation of this file.
1 /*!
2  \file lib/db/dbmi_base/ret_codes.c
3 
4  \brief DBMI Library (base) - return codes (internal use only)
5 
6  \todo Are we as restrictive here as for vector names?
7 
8  (C) 1999-2009, 2011 by the GRASS Development Team
9 
10  This program is free software under the GNU General Public License
11  (>=v2). Read the file COPYING that comes with GRASS for details.
12 
13  \author Joel Jones (CERL/UIUC), Radim Blazek
14  \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
15 */
16 
17 #include <stdlib.h>
18 #include <grass/dbmi.h>
19 #include "macros.h"
20 
21 /*!
22  \brief Send success code
23 
24  \return DB_OK
25 */
27 {
29  return DB_OK;
30 }
31 
32 /*!
33  \brief Send failure code
34 
35  \return DB_OK
36 */
38 {
41  return DB_OK;
42 }
43 
44 /*!
45  \brief Receive return code
46 
47  \param[out] ret_code return code
48 
49  \return DB_OK on success
50 */
51 int db__recv_return_code(int *ret_code)
52 {
53  dbString err_msg;
54 
55  /* get the return code first */
56  DB_RECV_INT(ret_code);
57 
58  /* if OK, we're done here */
59  if (*ret_code == DB_OK)
60  return DB_OK;
61 
62  /* should be DB_FAILED */
63  if (*ret_code != DB_FAILED) {
65  return DB_PROTOCOL_ERR;
66  }
67  /* get error message from driver */
68  db_init_string(&err_msg);
69  DB_RECV_STRING(&err_msg);
70 
71  db_error(db_get_string(&err_msg));
72  db_free_string(&err_msg);
73 
74  return DB_OK;
75 }
#define DB_PROTOCOL_ERR
Definition: dbmi.h:75
#define DB_SEND_INT(x)
Definition: macros.h:37
#define DB_SEND_C_STRING(x)
Definition: macros.h:16
void db_init_string(dbString *)
Initialize dbString.
Definition: string.c:25
int db__send_success()
Send success code.
Definition: ret_codes.c:26
#define DB_RECV_INT(x)
Definition: macros.h:39
int db__send_failure()
Send failure code.
Definition: ret_codes.c:37
char * db_get_string(const dbString *)
Get string.
Definition: string.c:140
int db__recv_return_code(int *ret_code)
Receive return code.
Definition: ret_codes.c:51
const char * db_get_error_msg(void)
Get error message.
void db_error(const char *)
Report error message.
#define DB_FAILED
Definition: dbmi.h:72
void db_protocol_error(void)
Report protocol error.
void db_free_string(dbString *)
Free allocated space for dbString.
Definition: string.c:150
#define DB_RECV_STRING(x)
Definition: macros.h:18
#define DB_OK
Definition: dbmi.h:71