forked from akalend/amqpcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMQPBase.cpp
62 lines (50 loc) · 1.13 KB
/
AMQPBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* AMQPBase.cpp
* librabbitmq++
*
* Created by Alexandre Kalendarev on 15.04.10.
*
*/
#include "AMQPcpp.h"
using namespace std;
AMQPBase::~AMQPBase() {
this->closeChannel();
}
void AMQPBase::checkReply(amqp_rpc_reply_t * res) {
checkClosed(res);
if (res->reply_type != AMQP_RESPONSE_NORMAL )
throw AMQPException(res);
}
void AMQPBase::checkClosed(amqp_rpc_reply_t * res) {
if( res->reply_type == AMQP_RESPONSE_SERVER_EXCEPTION && res->reply.id == AMQP_CHANNEL_CLOSE_METHOD )
opened=0;
}
void AMQPBase::openChannel() {
amqp_channel_open(*cnn, channelNum);
amqp_rpc_reply_t res = amqp_get_rpc_reply(*cnn);
if ( res.reply_type != AMQP_RESPONSE_NORMAL)
throw AMQPException(&res);
opened=1;
}
void AMQPBase::closeChannel() {
if (opened)
amqp_channel_close(*cnn, channelNum, AMQP_REPLY_SUCCESS);
}
void AMQPBase::reopen() {
if (opened) return;
AMQPBase::openChannel();
}
int AMQPBase::getChannelNum() {
return channelNum;
}
void AMQPBase::setParam(short param) {
this->parms=param;
}
string AMQPBase::getName() {
if (!name.size())
name="";
return name;
}
void AMQPBase::setName(string name) {
this->name=name;
}