-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmsBridge.cc
175 lines (143 loc) · 5.78 KB
/
XmsBridge.cc
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <xmsbridge.h>
using namespace std;
using namespace xms;
using namespace Nan;
namespace xmsbridge {
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
using v8::Handle;
Nan::Persistent<v8::Function> ListenerConfig::constructor;
Local<Object> wrapListenerConfig(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
v8::String::Utf8Value strchannel(args[0]);
char* channel = ToCString(strchannel);
xms::String* xmsChannel = new xms::String (channel);
cout << xmsChannel;
cout << "\n";
v8::String::Utf8Value strhost(args[1]);
char* host = ToCString(strhost);
xms::String* xmshost = new xms::String (host);
cout << xmshost;
cout << "\n";
v8::String::Utf8Value strport(args[2]);
char* port = ToCString(strport);
cout << port;
cout << "\n";
v8::String::Utf8Value strmgr(args[3]);
char* queuemgr = ToCString(strmgr);
xms::String* xmsqueuemgr = new xms::String (queuemgr);
cout << queuemgr;
cout << "\n";
v8::String::Utf8Value strdest(args[4]);
char* destination = ToCString(strdest);
xms::String* xmsdestination = new xms::String (destination);
cout << destination;
cout << "\n";
v8::String::Utf8Value listenerNameStr(args[5]);
char* name = ToCString(listenerNameStr);
std::string listenerName(name);
cout << "\n";
v8::Local<v8::Function> *callback = new Local<Function>(args[6].As<Function>());
cout << "create listener config";
Local<Object> listenerConfig = ListenerConfig::New(xmsqueuemgr,xmshost,xmsChannel,port,"7",xmsdestination, listenerName, callback);
return listenerConfig;
}
Local<Object> wrapConnection(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
v8::String::Utf8Value strchannel(args[0]);
char* channel = ToCString(strchannel);
xms::String* xmsChannel = new xms::String (channel);
cout << xmsChannel;
cout << "\n";
v8::String::Utf8Value strhost(args[1]);
char* host = ToCString(strhost);
xms::String* xmshost = new xms::String (host);
cout << xmshost;
cout << "\n";
v8::String::Utf8Value strport(args[2]);
char* port = ToCString(strport);
cout << port;
cout << "\n";
v8::String::Utf8Value strmgr(args[3]);
char* queuemgr = ToCString(strmgr);
xms::String* xmsqueuemgr = new xms::String (queuemgr);
cout << queuemgr;
cout << "\n";
v8::String::Utf8Value strdest(args[4]);
char* destination = ToCString(strdest);
xms::String* xmsdestination = new xms::String (destination);
cout << destination;
cout << "\n";
cout << "create xmsconnection";
Local<Object> xmsConnection = XmsConnection::New(xmsqueuemgr,xmshost,xmsChannel,port,"7",xmsdestination);
return xmsConnection;
}
void CreateListenerConfig(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Object> listenerConfigWrapper = wrapListenerConfig(args);
args.GetReturnValue().Set(listenerConfigWrapper);
}
void StartListener(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
xmsbridge::ListenerConfig* listenerConfig = Nan::ObjectWrap::Unwrap<xmsbridge::ListenerConfig>(args[0]->ToObject());
listenerConfig->createConnection();
listenerConfig->createSession();
listenerConfig->SetListener();
listenerConfig->startConnection();
listenerConfig->isolate = isolate;
args.GetReturnValue().Set(String::NewFromUtf8(isolate,"Success"));
}
void PrintConfig(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
xmsbridge::ListenerConfig* listenerConfig = Nan::ObjectWrap::Unwrap<xmsbridge::ListenerConfig>(args[0]->ToObject());
listenerConfig->PrintConfig();
args.GetReturnValue().Set(String::NewFromUtf8(isolate,"Success"));
}
void connectionWrapper(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Object> connection = wrapConnection(args);
args.GetReturnValue().Set(connection);
}
void startConnection(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
xmsbridge::XmsConnection* xmsConnection = node::ObjectWrap::Unwrap<XmsConnection>(args[0]->ToObject());
xmsConnection->startConnection();
args.GetReturnValue().Set(String::NewFromUtf8(isolate,"Success"));
}
void closeConnection(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
xmsbridge::XmsConnection* xmsConnection = node::ObjectWrap::Unwrap<XmsConnection>(args[0]->ToObject());
xmsConnection->closeConnection();
args.GetReturnValue().Set(String::NewFromUtf8(isolate,"Success"));
}
void receiveMessage(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
//Nan::Callback *callback = new Nan::Callback(args[1].As<Function>());
xmsbridge::XmsConnection* xmsConnection = node::ObjectWrap::Unwrap<XmsConnection>(args[0]->ToObject());
MessageReceiver *messageReceiver = new MessageReceiver();
char *message = messageReceiver->getMessage(xmsConnection);
std::string str(message);
cout << str;
cout << "\n";
//Nan::AsyncQueueWorker(new AsyncReceiver(messageReceiver, callback));
args.GetReturnValue().Set(String::NewFromUtf8(isolate, message));
}
void Init(Local<Object> exports, Local<Object> module) {
ListenerConfig::Init(exports);
XmsConnection::Init(exports);
NODE_SET_METHOD(exports, "CreateListenerConfig", CreateListenerConfig);
NODE_SET_METHOD(exports, "StartListener", StartListener);
NODE_SET_METHOD(exports, "PrintConfig", PrintConfig);
NODE_SET_METHOD(exports, "connectionWrapper", connectionWrapper);
NODE_SET_METHOD(exports, "startConnection", startConnection);
NODE_SET_METHOD(exports, "closeConnection", closeConnection);
NODE_SET_METHOD(exports, "receiveMessage", receiveMessage);
}
NODE_MODULE(xmsbridge, Init)
}