Navigation Menu

Skip to content

Commit

Permalink
actually doing the square
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekziade committed Feb 1, 2012
1 parent cba9483 commit b34c9e4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
28 changes: 27 additions & 1 deletion examples/square_worker.cpp
@@ -1,14 +1,40 @@
#include "Worker.h"


class SquareWorker: public powerhose::Worker {

protected:
void execute(vector<string>* vreq, vector<string>* vres);
public:
SquareWorker(const char* receiverChannel, const char* endPoint);
};


SquareWorker::SquareWorker(const char* receiverChannel, const char* endPoint) : Worker(receiverChannel, endPoint) {
//
};


void SquareWorker::execute(vector<string>* vreq, vector<string>* vres) {
int value;
string number = vreq->at(2);
stringstream ss(number);
ss >> value;
value *= value;
stringstream out;
out << value;
vres->push_back(out.str());
}


int main(int argc, const char* const argv[]) {


const char* receiver = "ipc://worker-cpp.ipc";
const char* endpoint = "ipc:///tmp/master-routing.ipc";

cout << "Creating a worker" << endl;
powerhose::Worker worker(receiver, endpoint);
SquareWorker worker(receiver, endpoint);

cout << "Let's run it" << endl;
worker.run();
Expand Down
4 changes: 2 additions & 2 deletions libhose/Worker.h
Expand Up @@ -37,8 +37,8 @@ namespace powerhose
zmq_pollitem_t poll_items[1];
void callMaster(string* request, string* response);
const char* receiverChannel;
protected:
void execute(vector<string>* vreq, vector<string>* vres);
protected:
virtual void execute(vector<string>* vreq, vector<string>* vres);

public:
Worker(const char* receiverChannel, const char* endPoint);
Expand Down
6 changes: 4 additions & 2 deletions libhose/util.cpp
Expand Up @@ -45,12 +45,14 @@ namespace powerhose
void unserialize(string* data, vector<string>* res) {
size_t found = 0;
int current = 0;
int size;
string sep = ":::";

while (found != string::npos) {
found = data->find_first_of(sep, current);
found = data->find_first_of(sep, current + 1);
if (found > 0) {
res->push_back(data->substr(current, found));
size = found - current;
res->push_back(data->substr(current, size));
current = found + sep.size();
}
}
Expand Down

0 comments on commit b34c9e4

Please sign in to comment.