Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
259 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,14 @@ old/ | |
.tox/ | ||
.cache/ | ||
.coverage | ||
*.o | ||
*.d | ||
*.egg | ||
*.egg-info/ | ||
*.pyc | ||
*.pyo | ||
*.class | ||
*.project | ||
*.cproject | ||
*~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
LIBRARY_NAME = rexterCppClient | ||
LIB_SRC_DIR = ./src/$(LIBRARY_NAME)/ | ||
TEST_DIR = ./src/test/ | ||
CXX = g++ | ||
CPPFLAGS = | ||
LIBS := -lzmq -ljson | ||
BUILD_DIR = ./build/ | ||
INCLUDES = -I/usr/local/include -I./$(LIB_SRC_DIR) | ||
INSTALL_DIR = /usr/local/ | ||
|
||
main: $(LIBRARY_NAME).so $(TEST_DIR)main.cpp | ||
$(CXX) $(INCLUDES) -o $(BUILD_DIR)main $(TEST_DIR)main.cpp -L$(BUILD_DIR) -l$(LIBRARY_NAME) $(LIBS) | ||
|
||
$(LIBRARY_NAME).so: $(LIB_SRC_DIR)/$(LIBRARY_NAME).cpp | ||
$(CXX) $(INCLUDES) -MMD -std=c++0x -pipe -fPIC -c $(LIB_SRC_DIR)/$(LIBRARY_NAME).cpp -o $(BUILD_DIR)$(LIBRARY_NAME).o $(LIBS) | ||
$(CXX) -shared -Wl,-soname=$(LIBRARY_NAME).so -o $(BUILD_DIR)$(LIBRARY_NAME).so $(BUILD_DIR)$(LIBRARY_NAME).o | ||
ln $(BUILD_DIR)$(LIBRARY_NAME).so $(BUILD_DIR)lib$(LIBRARY_NAME).so | ||
|
||
clean: | ||
rm $(BUILD_DIR)$(LIBRARY_NAME).o $(BUILD_DIR)$(LIBRARY_NAME).d $(BUILD_DIR)$(LIBRARY_NAME).so $(BUILD_DIR)lib$(LIBRARY_NAME).so $(BUILD_DIR)main | ||
|
||
install: | ||
sudo cp $(BUILD_DIR)$(LIBRARY_NAME).so $(BUILD_DIR)lib$(LIBRARY_NAME).so $(INSTALL_DIR)lib/ | ||
sudo cp $(LIB_SRC_DIR)/$(LIBRARY_NAME).h $(INSTALL_DIR)include/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//============================================================================ | ||
// Name : cppclient.cpp | ||
// Author : Andreas Hermann | ||
// Version : 0.1 | ||
// Copyright : | ||
// Description : Hello Neo4J. From C++ to Neo4J and back | ||
//============================================================================ | ||
|
||
// Bugs: send and receive always returns a EAGAIN error | ||
// Todo: fix EAGAIN error | ||
|
||
#include "rexterCppClient.h" | ||
|
||
rexterCppClient::rexterCppClient(std::string zsock_addr) | ||
: connected(false) | ||
{ | ||
connect(zsock_addr); | ||
} | ||
|
||
rexterCppClient::~rexterCppClient() | ||
{ | ||
if(connected) | ||
{ | ||
disconnect(); | ||
} | ||
} | ||
|
||
int rexterCppClient::connect(std::string zsock_addr) | ||
{ | ||
zcontext = zmq_init(1); | ||
if (!zcontext) { | ||
std::cout << "Error occurred during zmq_init(): " << zmq_strerror(zmq_errno()) << std::endl; | ||
return -1; | ||
} | ||
zsock = zmq_socket(zcontext, ZMQ_REQ); | ||
if (!zsock) { | ||
std::cout << "Error occurred during zmq_socket(): " << zmq_strerror(zmq_errno()) << std::endl; | ||
return -1; | ||
} | ||
if(zmq_connect(zsock, zsock_addr.c_str()) != 0) | ||
{ | ||
std::cout << "Error occurred during zmq_connect(): " << zmq_strerror(zmq_errno()) << std::endl; | ||
return -1; | ||
} | ||
connected = true; | ||
return 0; | ||
} | ||
|
||
int rexterCppClient::disconnect() | ||
{ | ||
if(connected) | ||
{ | ||
std::cout << "Disconnecting from zsock" << std::endl; | ||
zmq_close(zsock); | ||
zmq_term(zcontext); | ||
connected = false; | ||
} | ||
return 0; | ||
} | ||
|
||
int rexterCppClient::send_request(const Json::Value &path, const Json::Value ¶ms, const Json::Value &data, Json::Value &answer) | ||
{ | ||
|
||
// Code for sending: | ||
Json::Value js_msg(Json::objectValue); | ||
js_msg["data"] = data; | ||
js_msg["params"] = params; | ||
js_msg["path"] = path; | ||
std::string msg_to_send; | ||
msg_to_send = js_writer.write(js_msg); | ||
|
||
//std::cout << "Trying to send " << msg_to_send << std::endl; | ||
|
||
if(zmq_send(zsock, msg_to_send.c_str(), msg_to_send.length(), 0) != 0) | ||
{ | ||
std::cout << "Error sending message to server: " << zmq_errno() << " " | ||
<< zmq_strerror(zmq_errno()) << std::endl; | ||
//return -1; | ||
} | ||
|
||
// Code for receiving: | ||
zmq_msg_t message; | ||
zmq_msg_init(&message); | ||
if(zmq_recvmsg(zsock, &message, 0) != 0) | ||
{ | ||
std::cout << "Error receiving the answer from server: " | ||
<< zmq_strerror(zmq_errno()) << std::endl; | ||
//return -1; | ||
} | ||
std::string str_message(static_cast<char*> (zmq_msg_data(&message)), zmq_msg_size(&message)); | ||
zmq_msg_close (&message); | ||
|
||
// JSon parsing: | ||
Json::Value js_rcv; | ||
if(js_reader.parse(str_message, js_rcv, false)) | ||
{ | ||
std::cout << "Received: " << js_rcv << std::endl; // prints !!!Hello World!!! | ||
return 0; | ||
}else{ | ||
std::cout << "Error parsing the answer from server" << std::endl; | ||
return -1; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* cppclient.h | ||
* | ||
* Created on: 04.10.2011 | ||
* Author: hermann-local | ||
*/ | ||
|
||
#ifndef CPPCLIENT_H_ | ||
#define CPPCLIENT_H_ | ||
|
||
#include <iostream> | ||
#include "zmq.h" | ||
#include "stdio.h" | ||
#include "string.h" | ||
#include "json/json.h" | ||
|
||
|
||
class rexterCppClient | ||
{ | ||
public: | ||
|
||
rexterCppClient(std::string zsock_addr); | ||
~rexterCppClient(); | ||
|
||
// Send request and receive answer from server | ||
int send_request(const Json::Value &path, const Json::Value ¶ms, const Json::Value &data, Json::Value &answer); | ||
|
||
protected: | ||
|
||
private: | ||
|
||
// Open and close ZeroMQ socket connection | ||
int connect(std::string zsock_addr); | ||
int disconnect(); | ||
|
||
// Verbose | ||
void display_progress(); | ||
|
||
bool connected; | ||
void * zsock; | ||
void * zcontext; | ||
|
||
Json::FastWriter js_writer; | ||
Json::Reader js_reader; | ||
|
||
}; | ||
|
||
#endif /* CPPCLIENT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* main.cpp | ||
* | ||
* Created on: 04.10.2011 | ||
* Author: hermann-local | ||
*/ | ||
|
||
#include "rexterCppClient.h" | ||
|
||
int main(int argc, const char *argv[]) | ||
{ | ||
|
||
rexterCppClient* client = new rexterCppClient("tcp://localhost:5555"); | ||
|
||
Json::Value js_data(Json::objectValue); | ||
Json::Value js_params(Json::objectValue); | ||
Json::Value js_answer; | ||
|
||
Json::Value js_path("wordgraph/vertices/create"); | ||
js_data["city"] = "Dallas"; | ||
js_data["name"] = "Frank"; | ||
|
||
|
||
for( int i = 0; i < 1; i++) | ||
{ | ||
js_data["counter"] = i; | ||
client->send_request(js_path, js_params, js_data, js_answer); | ||
} | ||
delete client; | ||
|
||
return 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters