Annotation of parser3/src/types/pa_vamqp.h, revision 1.5
1.1 moko 1: /** @file
2: Parser: @b amqp class decls.
3:
1.2 moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.1 moko 5: Authors: Konstantin Morshnev <moko@design.ru>
6: */
7:
8: #ifndef PA_VAMQP_H
9: #define PA_VAMQP_H
10:
1.5 ! moko 11: #define IDENT_PA_VAMQP_H "$Id: pa_vamqp.h,v 1.4 2026/09/20 11:38:43 moko Exp $"
1.1 moko 12:
13: #include "classes.h"
14: #include "pa_vstateless_object.h"
1.3 moko 15: #include "pa_common.h"
1.1 moko 16:
1.5 ! moko 17: //for librabbitmq before 0.12
! 18: //#define PA_AMQP_COMPAT
! 19:
1.1 moko 20: #ifdef WITH_AMQP
1.5 ! moko 21:
! 22: #ifdef PA_AMQP_COMPAT
! 23:
1.1 moko 24: #include <amqp.h>
1.5 ! moko 25: #include <amqp_tcp_socket.h>
! 26: #include <amqp_framing.h>
! 27: #ifdef WITH_AMQP_SSL
! 28: #include <amqp_ssl_socket.h>
! 29: #endif
! 30:
! 31: #else
! 32:
! 33: #include <rabbitmq-c/amqp.h>
! 34: #include <rabbitmq-c/tcp_socket.h>
! 35: #include <rabbitmq-c/framing.h>
! 36: #ifdef WITH_AMQP_SSL
! 37: #include <rabbitmq-c/ssl_socket.h>
! 38: #endif
! 39:
! 40: #endif
! 41:
1.1 moko 42: #endif
43:
44: // defines
45: #define VAMQP_TYPE "amqp"
46:
47: // externs
48: extern Methoded *amqp_class;
49:
50: class VAmqp: public VStateless_object {
51: public:
52: // value
53: override const char* type() const { return VAMQP_TYPE; }
54: override VStateless_class *get_class() { return amqp_class; }
55:
56: #ifdef WITH_AMQP
57: public: // usage
1.3 moko 58:
59: // ALIVE: usable right now
60: // CHANNEL_DEAD: last operation got a channel-level error - reopening the channel (same connection) is required
61: // CONNECTION_DEAD: last operation got a connection-level error - a full reconnect is required
62: enum ConnState { ALIVE, CHANNEL_DEAD, CONNECTION_DEAD };
63:
64: VAmqp(): fconnection(0), fchannel(0), fstate(CONNECTION_DEAD), fcreate_options(0), freconnect_interval(0) {}
1.1 moko 65: ~VAmqp() {}
66:
67: amqp_connection_state_t fconnection;
1.4 moko 68: amqp_channel_t fchannel;
1.1 moko 69: bool fstop;
1.3 moko 70: ConnState fstate;
71: HashStringValue* fcreate_options;
72: int freconnect_interval; // 0 = auto-reconnect disabled, N>0 = enabled, sleeps N sec before each attempt
73:
74: void ensure_connected();
1.1 moko 75:
76: amqp_connection_state_t connection() {
77: if(!fconnection)
78: throw Exception(PARSER_RUNTIME, 0, "using uninitialized amqp object");
1.3 moko 79: ensure_connected();
1.1 moko 80: return fconnection;
81: }
82:
1.4 moko 83: amqp_channel_t channel() {
1.1 moko 84: if(!fchannel)
85: throw Exception(PARSER_RUNTIME, 0, "using uninitialized amqp object channel");
1.3 moko 86: ensure_connected();
1.1 moko 87: return fchannel;
88: }
89:
90: #endif // WITH_AMQP
91: };
92:
93: #endif
94:
95:
E-mail: