diff --git a/examples/square_worker.cpp b/examples/square_worker.cpp index c5f4fae..1f08347 100644 --- a/examples/square_worker.cpp +++ b/examples/square_worker.cpp @@ -1,6 +1,32 @@ #include "Worker.h" +class SquareWorker: public powerhose::Worker { + + protected: + void execute(vector* vreq, vector* vres); + public: + SquareWorker(const char* receiverChannel, const char* endPoint); +}; + + +SquareWorker::SquareWorker(const char* receiverChannel, const char* endPoint) : Worker(receiverChannel, endPoint) { + // +}; + + +void SquareWorker::execute(vector* vreq, vector* 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[]) { @@ -8,7 +34,7 @@ int main(int argc, const char* const argv[]) { 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(); diff --git a/libhose/Worker.h b/libhose/Worker.h index 4befae4..40d35b6 100644 --- a/libhose/Worker.h +++ b/libhose/Worker.h @@ -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* vreq, vector* vres); + protected: + virtual void execute(vector* vreq, vector* vres); public: Worker(const char* receiverChannel, const char* endPoint); diff --git a/libhose/util.cpp b/libhose/util.cpp index 7a9fd3d..8398ad8 100644 --- a/libhose/util.cpp +++ b/libhose/util.cpp @@ -45,12 +45,14 @@ namespace powerhose void unserialize(string* data, vector* 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(); } }