diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..259bdce --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.cproject +.project +Debug +Release diff --git a/main.cpp b/main.cpp index 2d443ea..2cde54a 100644 --- a/main.cpp +++ b/main.cpp @@ -29,12 +29,37 @@ using namespace metacall; +// +// Serialization +// + +namespace metacall { + + +bool serialize(Serializer* serializer, const char str[]) { + serializer->writeRaw(str, strlen(str) + 1); + return true; +} + +bool deserialize(Deserializer* deserializer, const char ** str) { + *str = reinterpret_cast(deserializer->readRaw(1)); + if (*str == NULL) { + return false; + } + + return deserializer->readRaw(strlen(*str)) != NULL; +} + + +} + + // // Local functions // -static void serverTest1(int value) { - printf("Server function %d\n", value); +static void serverTest1(const char str[], int num) { + printf("Server function params are \"%s\" and \"%d\"\n", str, num); } @@ -60,7 +85,7 @@ int main(int argc, char *argv[]) { server.binding()->bind(FPARAM(serverTest1)); do { - client.protocol()->invoke("serverTest1", 1234); + client.protocol()->invoke("serverTest1", "OneTwoThreeFour", 1234); server.advance(); client.advance(); } diff --git a/mc_protocol.cpp b/mc_protocol.cpp index e8eb152..e2eddf1 100644 --- a/mc_protocol.cpp +++ b/mc_protocol.cpp @@ -77,6 +77,10 @@ void Protocol::setRate(int rate) { rate_ = rate; } +bool Protocol::pendingTasks() const { + return taskMap_.size() > 0; +} + bool Protocol::setHandler(TaskId id, HandlerProc handler, void* userPtr) { const TaskMap::iterator iter = taskMap_.find(id); if (iter == taskMap_.end() || iter->second.state != TASK_STATE_PENDING) { @@ -100,11 +104,6 @@ void Protocol::clearHandlers() { } } -Protocol::TaskState Protocol::queryState(TaskId id) const { - const TaskMap::const_iterator iter = taskMap_.find(id); - return iter == taskMap_.end() ? TASK_STATE_UNDEFINED : iter->second.state; -} - Stream::State Protocol::advanceStream() { stream_->advance(); diff --git a/mc_protocol.hpp b/mc_protocol.hpp index a61f406..c3cc595 100644 --- a/mc_protocol.hpp +++ b/mc_protocol.hpp @@ -55,15 +55,15 @@ public: Protocol(Stream* stream, Binding* binding); void advance (); - void setRate (int rate); - bool setHandler (TaskId id, HandlerProc handler, void* userPtr = NULL); - void clearHandler (TaskId id); - void clearHandlers (); template TaskState queryResult (TaskId id, R* result); - TaskState queryState (TaskId id) const; + bool pendingTasks () const; + + bool setHandler (TaskId id, HandlerProc handler, void* userPtr = NULL); + void clearHandler (TaskId id); + void clearHandlers (); TaskId invoke (const Token& token); template