XTA: API Reference for C language

xta_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 /* system includes */
27 #ifdef HAVE_GLIB_H
28 # include <glib.h>
29 #endif
30 /* LIXA includes */
31 #include "lixa_errors.h"
32 #include "lixa_trace.h"
33 /* XTA includes */
34 #include "xta_xa_resource.h"
35 
36 
37 
38 /* set module trace flag */
39 #ifdef LIXA_TRACE_MODULE
40 # undef LIXA_TRACE_MODULE
41 #endif /* LIXA_TRACE_MODULE */
42 #define LIXA_TRACE_MODULE LIXA_TRACE_MOD_XTA
43 
44 
45 
47  int native)
48 {
49  enum Exception { NULL_OBJECT
50  , NONE } excp;
51  int ret_cod = LIXA_RC_INTERNAL_ERROR;
52 
53  LIXA_TRACE(("xta_xa_resource_init\n"));
54  TRY {
55  if (NULL == xa_resource)
56  THROW(NULL_OBJECT);
57  /* set resource description (first part) */
58  xa_resource->rsrmgr_config.name = NULL;
59  xa_resource->rsrmgr_config.switch_file = NULL;
60  xa_resource->rsrmgr_config.xa_open_info[0] = '\0';
61  xa_resource->rsrmgr_config.xa_close_info[0] = '\0';
62  /* set resource description (second part) */
63  xa_resource->act_rsrmgr_config.generic = &xa_resource->rsrmgr_config;
64  xa_resource->act_rsrmgr_config.module = NULL;
65  lixa_iface_reset(&xa_resource->act_rsrmgr_config.lixa_iface);
66  /* set dynamic to TRUE: XTA is typically dynamic with few exceptions */
67  xa_resource->dynamic = TRUE;
68  xa_resource->enlisted_tx = NULL;
69 
70  THROW(NONE);
71  } CATCH {
72  switch (excp) {
73  case NULL_OBJECT:
74  ret_cod = LIXA_RC_NULL_OBJECT;
75  break;
76  case NONE:
77  ret_cod = LIXA_RC_OK;
78  break;
79  default:
80  ret_cod = LIXA_RC_INTERNAL_ERROR;
81  } /* switch (excp) */
82  } /* TRY-CATCH */
83  LIXA_TRACE(("xta_xa_resource_init/excp=%d/"
84  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
85  return ret_cod;
86 }
87 
88 
89 
91  const xta_xa_resource_t *xa_resource)
92 {
93  enum Exception { NULL_OBJECT
94  , NONE } excp;
95  int ret_cod = LIXA_RC_INTERNAL_ERROR;
96  const xta_xa_resource_config_t *config = NULL;
97 
98  LIXA_TRACE(("xta_xa_resource_get_config\n"));
99  TRY {
100  if (NULL == xa_resource)
101  THROW(NULL_OBJECT);
102  /* duplicate the config structs */
103 
104  /* return the copy of the config structs */
105  config = &xa_resource->act_rsrmgr_config;
106 
107  THROW(NONE);
108  } CATCH {
109  switch (excp) {
110  case NULL_OBJECT:
111  ret_cod = LIXA_RC_NULL_OBJECT;
112  break;
113  case NONE:
114  ret_cod = LIXA_RC_OK;
115  break;
116  default:
117  ret_cod = LIXA_RC_INTERNAL_ERROR;
118  } /* switch (excp) */
119  } /* TRY-CATCH */
120  LIXA_TRACE(("xta_xa_resource_get_config/excp=%d/"
121  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
122  return config;
123 }
124 
125 
126 
128  const xta_transaction_t *tx)
129 {
130  enum Exception { NULL_OBJECT1
131  , NULL_OBJECT2
132  , RESOURCE_ALREADY_REGISTERED
133  , NONE } excp;
134  int ret_cod = LIXA_RC_INTERNAL_ERROR;
135 
136  LIXA_TRACE(("xta_xa_resource_enlisted\n"));
137  TRY {
138  if (NULL == xa_resource)
139  THROW(NULL_OBJECT1);
140  if (NULL == tx)
141  THROW(NULL_OBJECT2);
142  if (NULL != xa_resource->enlisted_tx) {
143  /* already registered resource, checking the Transaction Manager */
144  if (tx != xa_resource->enlisted_tx) {
145  LIXA_TRACE(("xta_xa_resource_enlisted: this resource has "
146  "been already registered by another TX: %p\n",
147  xa_resource->enlisted_tx));
148  THROW(RESOURCE_ALREADY_REGISTERED);
149  } else {
150  LIXA_TRACE(("xta_xa_resource_enlisted: this resource has "
151  "been already registered by this TX, "
152  "skipping...\n"));
153  } /* if (tm != xa_resource->registered_tx) */
154  } else {
155  xa_resource->enlisted_tx = tx;
156  LIXA_TRACE(("xta_xa_resource_enlisted: this resource is now "
157  "registered by TX %p\n", xa_resource->enlisted_tx));
158  } /* if (NULL != xa_resource->registered_tx) */
159 
160  THROW(NONE);
161  } CATCH {
162  switch (excp) {
163  case NULL_OBJECT1:
164  case NULL_OBJECT2:
165  ret_cod = LIXA_RC_NULL_OBJECT;
166  break;
167  case RESOURCE_ALREADY_REGISTERED:
169  break;
170  case NONE:
171  ret_cod = LIXA_RC_OK;
172  break;
173  default:
174  ret_cod = LIXA_RC_INTERNAL_ERROR;
175  } /* switch (excp) */
176  } /* TRY-CATCH */
177  LIXA_TRACE(("xta_xa_resource_enlisted/excp=%d/"
178  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
179  return ret_cod;
180 }
181 
182 
183 
185 {
186  enum Exception { NULL_OBJECT
187  , NONE } excp;
188  int ret_cod = LIXA_RC_INTERNAL_ERROR;
189 
190  LIXA_TRACE(("xta_xa_resource_clean\n"));
191  TRY {
192  /* check the object is not null */
193  if (NULL == xa_resource)
194  THROW(NULL_OBJECT);
195 
196  THROW(NONE);
197  } CATCH {
198  switch (excp) {
199  case NULL_OBJECT:
200  ret_cod = LIXA_RC_NULL_OBJECT;
201  break;
202  case NONE:
203  ret_cod = LIXA_RC_OK;
204  break;
205  default:
206  ret_cod = LIXA_RC_INTERNAL_ERROR;
207  } /* switch (excp) */
208  } /* TRY-CATCH */
209  LIXA_TRACE(("xta_xa_resource_clean/excp=%d/"
210  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
211  return;
212 }
213 
214 
215 
217  const xta_xid_t *xid,
218  long flag)
219 {
220  enum Exception { NONE } excp;
221  int ret_cod = LIXA_RC_INTERNAL_ERROR;
222 
223  LIXA_TRACE(("xta_xa_resource_start\n"));
224  TRY {
225 
226  THROW(NONE);
227  } CATCH {
228  switch (excp) {
229  case NONE:
230  ret_cod = LIXA_RC_OK;
231  break;
232  default:
233  ret_cod = LIXA_RC_INTERNAL_ERROR;
234  } /* switch (excp) */
235  } /* TRY-CATCH */
236  LIXA_TRACE(("xta_xa_resource_start/excp=%d/"
237  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
238  return ret_cod;
239 }
240 
241 
242 
244  const xta_xid_t *xid,
245  long flag)
246 {
247  enum Exception { NONE } excp;
248  int ret_cod = LIXA_RC_INTERNAL_ERROR;
249 
250  LIXA_TRACE(("xta_xa_resource_end\n"));
251  TRY {
252 
253  THROW(NONE);
254  } CATCH {
255  switch (excp) {
256  case NONE:
257  ret_cod = LIXA_RC_OK;
258  break;
259  default:
260  ret_cod = LIXA_RC_INTERNAL_ERROR;
261  } /* switch (excp) */
262  } /* TRY-CATCH */
263  LIXA_TRACE(("xta_xa_resource_end/excp=%d/"
264  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
265  return ret_cod;
266 }
267 
268 
269 
271  const xta_xid_t *xid)
272 {
273  enum Exception { NONE } excp;
274  int ret_cod = LIXA_RC_INTERNAL_ERROR;
275 
276  LIXA_TRACE(("xta_xa_resource_prepare\n"));
277  TRY {
278 
279  THROW(NONE);
280  } CATCH {
281  switch (excp) {
282  case NONE:
283  ret_cod = LIXA_RC_OK;
284  break;
285  default:
286  ret_cod = LIXA_RC_INTERNAL_ERROR;
287  } /* switch (excp) */
288  } /* TRY-CATCH */
289  LIXA_TRACE(("xta_xa_resource_prepare/excp=%d/"
290  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
291  return ret_cod;
292 }
293 
294 
295 
297  const xta_xid_t *xid,
298  int one_phase)
299 {
300  enum Exception { NONE } excp;
301  int ret_cod = LIXA_RC_INTERNAL_ERROR;
302 
303  LIXA_TRACE(("xta_xa_resource_commit\n"));
304  TRY {
305 
306  THROW(NONE);
307  } CATCH {
308  switch (excp) {
309  case NONE:
310  ret_cod = LIXA_RC_OK;
311  break;
312  default:
313  ret_cod = LIXA_RC_INTERNAL_ERROR;
314  } /* switch (excp) */
315  } /* TRY-CATCH */
316  LIXA_TRACE(("xta_xa_resource_commit/excp=%d/"
317  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
318  return ret_cod;
319 }
320 
int xta_xa_resource_end(xta_xa_resource_t *xa_resource, const xta_xid_t *xid, long flag)
int xta_xa_resource_commit(xta_xa_resource_t *xa_resource, const xta_xid_t *xid, int one_phase)
#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
void lixa_iface_reset(lixa_iface_t *iface)
int xta_xa_resource_prepare(xta_xa_resource_t *xa_resource, const xta_xid_t *xid)
int xta_xa_resource_start(xta_xa_resource_t *xa_resource, const xta_xid_t *xid, long flag)
const xta_xa_resource_config_t * xta_xa_resource_get_config(const xta_xa_resource_t *xa_resource)
struct act_rsrmgr_config_s act_rsrmgr_config
struct act_rsrmgr_config_s xta_xa_resource_config_t
void xta_xa_resource_clean(xta_xa_resource_t *xa_resource)
struct rsrmgr_config_s rsrmgr_config
#define LIXA_RC_RESOURCE_ALREADY_REGISTERED
Definition: lixa_errors.h:576
const xta_transaction_t * enlisted_tx
int xta_xa_resource_enlisted(xta_xa_resource_t *xa_resource, const xta_transaction_t *tx)

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