home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 March / VPR0303A.ISO / AIBO / MoNet / MotionAgents / MotionAgents.cc < prev    next >
C/C++ Source or Header  |  2002-12-19  |  2KB  |  99 lines

  1. //
  2. // Copyright 2002 Sony Corporation 
  3. //
  4. // Permission to use, copy, modify, and redistribute this software for
  5. // non-commercial use is hereby granted.
  6. //
  7. // This software is provided "as is" without warranty of any kind,
  8. // either expressed or implied, including but not limited to the
  9. // implied warranties of fitness for a particular purpose.
  10. //
  11.  
  12. #include <OPENR/OSyslog.h>
  13. #include <OPENR/core_macro.h>
  14. #include <MoNetData.h>
  15. #include "MotionAgents.h"
  16.  
  17. MotionAgents::MotionAgents() : motionAgentsState(MAS_IDLE),
  18.                                moNetAgentManager(), neutralAgent(), mtnAgent()
  19. {
  20. }
  21.  
  22. OStatus
  23. MotionAgents::DoInit(const OSystemEvent& event)
  24. {
  25.     NEW_ALL_SUBJECT_AND_OBSERVER;
  26.     REGISTER_ALL_ENTRY;
  27.     SET_ALL_READY_AND_NOTIFY_ENTRY;
  28.  
  29.     moNetAgentManager.RegisterMoNetAgent(&neutralAgent);
  30.     moNetAgentManager.RegisterMoNetAgent(&mtnAgent);
  31.     moNetAgentManager.Init();
  32.  
  33.     return oSUCCESS;
  34. }
  35.  
  36. OStatus
  37. MotionAgents::DoStart(const OSystemEvent& event)
  38. {
  39.     moNetAgentManager.Start(subject[sbjEffector]);
  40.     motionAgentsState = MAS_START;
  41.  
  42.     ENABLE_ALL_SUBJECT;
  43.     ASSERT_READY_TO_ALL_OBSERVER;
  44.  
  45.     return oSUCCESS;
  46. }
  47.  
  48. OStatus
  49. MotionAgents::DoStop(const OSystemEvent& event)
  50. {
  51.     motionAgentsState = MAS_IDLE;
  52.  
  53.     DISABLE_ALL_SUBJECT;
  54.     DEASSERT_READY_TO_ALL_OBSERVER;
  55.  
  56.     return oSUCCESS;
  57. }
  58.  
  59. OStatus
  60. MotionAgents::DoDestroy(const OSystemEvent& event)
  61. {
  62.     DELETE_ALL_SUBJECT_AND_OBSERVER;
  63.     return oSUCCESS;
  64. }
  65.  
  66. void
  67. MotionAgents::NotifyCommand(const ONotifyEvent& event)
  68. {
  69.     OSYSDEBUG(("MotionAgents::NotifyCommand()\n"));
  70.  
  71.     if (motionAgentsState == MAS_START) {
  72.  
  73.         MoNetAgentResult result;
  74.         moNetAgentManager.NotifyCommand(event, &result);
  75.         if (result.status != monetSUCCESS) {
  76.             subject[sbjResult]->SetData(&result, sizeof(result));
  77.             subject[sbjResult]->NotifyObservers();
  78.         }
  79.  
  80.         observer[event.ObsIndex()]->AssertReady();
  81.     }
  82. }
  83.  
  84. void
  85. MotionAgents::ReadyEffector(const OReadyEvent& event)
  86. {
  87.     OSYSDEBUG(("MotionAgents::ReadyEffector()\n"));
  88.  
  89.     if (motionAgentsState == MAS_START) {
  90.  
  91.         MoNetAgentResult result;
  92.         moNetAgentManager.ReadyEffector(event, &result);
  93.         if (result.status != monetSUCCESS) {
  94.             subject[sbjResult]->SetData(&result, sizeof(result));
  95.             subject[sbjResult]->NotifyObservers();
  96.         }
  97.     }
  98. }
  99.