arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Messenger.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include "Messenger.h"
00004 #include "Communicator.h"
00005 #include "KokoBuffer.h"
00006 
00007 using namespace std;
00008 
00009 
00010 // -----------------
00011 // --- Messenger ---
00012 // -----------------
00013 //
00014 Messenger::Messenger(Communicator *cator, unsigned int bufsize)
00015   : _com(cator), _kbuf(bufsize)
00016 {
00017 
00018 }
00019 
00020 
00021 // ------------------
00022 // --- ~Messenger ---
00023 // ------------------
00024 //
00025 Messenger::~Messenger(void)
00026 {
00027   // Note, don't delete communicator we're passed it 
00028   // in the constructor so we'll leave it to others
00029   // to clean up. 
00030   
00031 }
00032 
00033 
00034 // ----------------------
00035 // --- WaitForMessage ---
00036 // ----------------------
00037 //
00038 void Messenger::WaitForMessage(void)
00039 {
00040   // Wait for a message to show up...
00041   unsigned int nbytes = _com->Recv(KOKO_ANY_ID, _kbuf, KOKO_ANY_TAG);
00042 
00043   // We have a message, snag the tag and lookup the callback. 
00044   KokoTag tag = _com->RecvTag();
00045   _cbmap.Invoke(tag, _kbuf);
00046 }
00047 
00048 
00049 // ------------------------
00050 // --- WaitForBroadcast ---
00051 // ------------------------
00052 //
00053 void Messenger::WaitForBroadcast(void)
00054 {
00055   // Wait for a message to show up...
00056   KokoTag dummy;
00057   unsigned int nbytes = _com->Broadcast(_kbuf, 0, dummy);
00058 
00059   // We have a message, snag the tag and lookup the callback. 
00060   KokoTag tag = _com->RecvTag();
00061   _cbmap.Invoke(tag, _kbuf);
00062 }

Send questions, comments, and bug reports to:
jmk