XTA: API Reference for C language

xta_acquired_xa_resource.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2019, Christian Ferrari <tiian@users.sourceforge.net>
3  * All rights reserved.
4  *
5  * This file is part of LIXA.
6  *
7  * LIXA is free software: you can redistribute this file and/or modify
8  * it under the terms of the GNU Lesser General Public License version 2.1 as
9  * published by the Free Software Foundation.
10  *
11  * LIXA is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with LIXA. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "config.h"
20 
21 
22 
23 #ifdef HAVE_ERRNO_H
24 # include <errno.h>
25 #endif
26 #ifdef HAVE_STRING_H
27 # include <string.h>
28 #endif
29 
30 
31 
32 /* LIXA includes */
33 #include "lixa_errors.h"
34 #include "lixa_trace.h"
35 /* XTA includes */
37 
38 
39 
40 /* set module trace flag */
41 #ifdef LIXA_TRACE_MODULE
42 # undef LIXA_TRACE_MODULE
43 #endif /* LIXA_TRACE_MODULE */
44 #define LIXA_TRACE_MODULE LIXA_TRACE_MOD_XTA
45 
46 
47 
49  const struct xta_iface_s *iface,
50  const char *name,
51  const char *open_info)
52 {
53  enum Exception { NULL_OBJECT1
54  , OBJ_CORRUPTED
55  , NULL_OBJECT2
56  , INVALID_OPTION1
57  , INVALID_OPTION2
58  , XTA_XA_RESOURCE_INIT_ERROR
59  , XML_STRDUP_ERROR
60  , NONE } excp;
61  int ret_cod = LIXA_RC_INTERNAL_ERROR;
62 
63  LIXA_TRACE(("xta_acquired_xa_resource_init\n"));
64  TRY {
65  if (NULL == xa_resource)
66  THROW(NULL_OBJECT1);
67  /* check the object has not already been initialized */
68  if (NULL != xa_resource->xa_resource.rsrmgr_config.name)
69  THROW(OBJ_CORRUPTED);
70  /* interface can't be NULL */
71  if (NULL == iface)
72  THROW(NULL_OBJECT2);
73  /* name can't be NULL or empty */
74  if (NULL == name || 0 == strlen(name))
75  THROW(INVALID_OPTION1);
76  /* open_info can't be NULL or empty */
77  if (NULL == open_info || 0 == strlen(open_info))
78  THROW(INVALID_OPTION2);
79  if (strlen(open_info) >= MAXINFOSIZE) {
80  LIXA_TRACE(("xta_acquired_xa_resource_init: option open_info "
81  "(" SIZE_T_FORMAT ")"
82  "exceeds MAXINFOSIZE %d\n", strlen(open_info),
83  MAXINFOSIZE));
84  }
85  /*
86  * call parent initializator
87  * Acquired XA Resources don't generally need explicit
88  * xa_open, xa_close
89  */
90  LIXA_TRACE(("xta_acquired_xa_resource_init: name='%s', "
91  "open_info='%s'\n", name, open_info));
92  if (LIXA_RC_OK != (ret_cod = xta_xa_resource_init(
93  (xta_xa_resource_t *)xa_resource, FALSE)))
94  THROW(XTA_XA_RESOURCE_INIT_ERROR);
95  /* set object properties */
96  xa_resource->iface = iface;
97  if (NULL == (xa_resource->xa_resource.rsrmgr_config.name =
98  xmlCharStrdup(name)))
99  THROW(XML_STRDUP_ERROR);
100  strncpy(xa_resource->xa_resource.rsrmgr_config.xa_open_info,
101  open_info, MAXINFOSIZE);
102  xa_resource->xa_resource.rsrmgr_config.xa_open_info[MAXINFOSIZE-1] =
103  '\0';
104 
105  THROW(NONE);
106  } CATCH {
107  switch (excp) {
108  case NULL_OBJECT1:
109  ret_cod = LIXA_RC_NULL_OBJECT;
110  break;
111  case OBJ_CORRUPTED:
112  ret_cod = LIXA_RC_OBJ_CORRUPTED;
113  break;
114  case NULL_OBJECT2:
115  ret_cod = LIXA_RC_NULL_OBJECT;
116  break;
117  case INVALID_OPTION1:
118  case INVALID_OPTION2:
119  ret_cod = LIXA_RC_INVALID_OPTION;
120  break;
121  case XTA_XA_RESOURCE_INIT_ERROR:
122  break;
123  case XML_STRDUP_ERROR:
124  ret_cod = LIXA_RC_XML_STRDUP_ERROR;
125  break;
126  case NONE:
127  ret_cod = LIXA_RC_OK;
128  break;
129  default:
130  ret_cod = LIXA_RC_INTERNAL_ERROR;
131  } /* switch (excp) */
132  } /* TRY-CATCH */
133  LIXA_TRACE(("xta_acquired_xa_resource_init/excp=%d/"
134  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
135  return ret_cod;
136 }
137 
138 
139 
141 {
142  enum Exception { NULL_OBJECT
143  , NONE } excp;
144  int ret_cod = LIXA_RC_INTERNAL_ERROR;
145 
146  LIXA_TRACE(("xta_acquired_xa_resource_clean\n"));
147  TRY {
148  if (NULL == xa_resource)
149  THROW(NULL_OBJECT);
150  if (NULL != xa_resource->xa_resource.rsrmgr_config.name) {
151  g_free(xa_resource->xa_resource.rsrmgr_config.name);
152  xa_resource->xa_resource.rsrmgr_config.name = NULL;
153  }
154  xa_resource->xa_resource.rsrmgr_config.xa_open_info[0] = '\0';
155 
156  THROW(NONE);
157  } CATCH {
158  switch (excp) {
159  case NULL_OBJECT:
160  ret_cod = LIXA_RC_NULL_OBJECT;
161  break;
162  case NONE:
163  ret_cod = LIXA_RC_OK;
164  break;
165  default:
166  ret_cod = LIXA_RC_INTERNAL_ERROR;
167  } /* switch (excp) */
168  } /* TRY-CATCH */
169  LIXA_TRACE(("xta_acquired_xa_resource_clean/excp=%d/"
170  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
171  return;
172 }
173 
#define LIXA_RC_XML_STRDUP_ERROR
Definition: lixa_errors.h:498
#define LIXA_RC_NULL_OBJECT
Definition: lixa_errors.h:139
#define LIXA_RC_INTERNAL_ERROR
Definition: lixa_errors.h:122
int xta_xa_resource_init(xta_xa_resource_t *xa_resource, int native)
#define LIXA_RC_OK
Definition: lixa_errors.h:115
#define LIXA_RC_OBJ_CORRUPTED
Definition: lixa_errors.h:155
void xta_acquired_xa_resource_clean(xta_acquired_xa_resource_t *xa_resource)
const struct xta_iface_s * iface
#define MAXINFOSIZE
Definition: xa.h:67
int xta_acquired_xa_resource_init(xta_acquired_xa_resource_t *xa_resource, const struct xta_iface_s *iface, const char *name, const char *open_info)
#define LIXA_RC_INVALID_OPTION
Definition: lixa_errors.h:163
struct rsrmgr_config_s rsrmgr_config
char name[RMNAMESZ]
Definition: xa.h:78

Copyright © 2009-2019, Christian Ferrari tiian@users.sourceforge.net http://www.tiian.org/