Next: 3.3.8 SampleObserverのソース
Up: 3.3 オブジェクト間通信
Previous: 3.3.6.3 3.SampleSubject::Ready()
[SampleSubject.h]
#include <OPENR/OObject.h>
#include <OPENR/OSubject.h>
#include <OPENR/OObserver.h>
#include "def.h"
class SampleSubject : public OObject {
public:
SampleSubject();
virtual ~SampleSubject() {}
OSubject* subject[numOfSubject];
OObserver* observer[numOfObserver];
virtual OStatus DoInit (const OSystemEvent& event);
virtual OStatus DoStart (const OSystemEvent& event);
virtual OStatus DoStop (const OSystemEvent& event);
virtual OStatus DoDestroy(const OSystemEvent& event);
void Ready(const OReadyEvent& event);
};
[SampleSubject.cc]
#include <string.h>
#include <OPENR/OSyslog.h>
#include <OPENR/core_macro.h>
#include "SampleSubject.h"
SampleSubject::SampleSubject()
{
}
OStatus
SampleSubject::DoInit(const OSystemEvent& event)
{
NEW_ALL_SUBJECT_AND_OBSERVER;
REGISTER_ALL_ENTRY;
SET_ALL_READY_AND_NOTIFY_ENTRY;
return oSUCCESS;
}
OStatus
SampleSubject::DoStart(const OSystemEvent& event)
{
ENABLE_ALL_SUBJECT;
ASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
}
OStatus
SampleSubject::DoStop(const OSystemEvent& event)
{
DISABLE_ALL_SUBJECT;
DEASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
}
OStatus
SampleSubject::DoDestroy(const OSystemEvent& event)
{
DELETE_ALL_SUBJECT_AND_OBSERVER;
return oSUCCESS;
}
void
SampleSubject::Ready(const OReadyEvent& event)
{
OSYSPRINT(("SampleSubject::Ready() : %s\n",
event.IsAssert() ? "ASSERT READY" :
"DEASSERT READY"));
static int counter = 0;
char str[32];
if (counter == 0) {
strcpy(str, "!!! Hello world !!!");
subject[sbjSendString]->SetData(str,sizeof(str));
subject[sbjSendString]->NotifyObservers();
} else if (counter == 1) {
strcpy(str, "!!! Hello world again !!!");
subject[sbjSendString]->SetData(str,sizeof(str));
subject[sbjSendString]->NotifyObservers();
}
counter++;
}
generated through LaTeX2HTML. M.Inaba 平成18年5月6日