This commit is contained in:
Alex Yatskov 2011-09-17 10:09:28 -07:00
parent 39783bccb4
commit 7c74004488
4 changed files with 41 additions and 13 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.cproject
.project
Debug
Release

View File

@ -29,12 +29,37 @@
using namespace metacall; 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<const char*>(deserializer->readRaw(1));
if (*str == NULL) {
return false;
}
return deserializer->readRaw(strlen(*str)) != NULL;
}
}
// //
// Local functions // Local functions
// //
static void serverTest1(int value) { static void serverTest1(const char str[], int num) {
printf("Server function %d\n", value); 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)); server.binding()->bind(FPARAM(serverTest1));
do { do {
client.protocol()->invoke("serverTest1", 1234); client.protocol()->invoke("serverTest1", "OneTwoThreeFour", 1234);
server.advance(); server.advance();
client.advance(); client.advance();
} }

View File

@ -77,6 +77,10 @@ void Protocol::setRate(int rate) {
rate_ = rate; rate_ = rate;
} }
bool Protocol::pendingTasks() const {
return taskMap_.size() > 0;
}
bool Protocol::setHandler(TaskId id, HandlerProc handler, void* userPtr) { bool Protocol::setHandler(TaskId id, HandlerProc handler, void* userPtr) {
const TaskMap::iterator iter = taskMap_.find(id); const TaskMap::iterator iter = taskMap_.find(id);
if (iter == taskMap_.end() || iter->second.state != TASK_STATE_PENDING) { 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::State Protocol::advanceStream() {
stream_->advance(); stream_->advance();

View File

@ -55,15 +55,15 @@ public:
Protocol(Stream* stream, Binding* binding); Protocol(Stream* stream, Binding* binding);
void advance (); void advance ();
void setRate (int rate); void setRate (int rate);
bool setHandler (TaskId id, HandlerProc handler, void* userPtr = NULL);
void clearHandler (TaskId id);
void clearHandlers ();
template <typename R> template <typename R>
TaskState queryResult (TaskId id, R* result); 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); TaskId invoke (const Token& token);
template <typename P1> template <typename P1>