Ejemplo n.º 1
0
TEST_F(FSEventsTests, test_fsevents_event_action) {
  // Assume event type is registered.
  StartEventLoop();

  // Simulate registering an event subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  auto status = sub->init();

  auto sc = sub->GetSubscription(real_test_path, 0);
  EventFactory::registerEventSubscriber(sub);

  sub->subscribe(&TestFSEventsEventSubscriber::Callback, sc);
  event_pub_->configure();

  CreateEvents();
  sub->WaitForEvents(kMaxEventLatency, 1);

  // Make sure the fsevents action was expected.
  ASSERT_TRUE(sub->actions_.size() > 0);
  bool has_created = false;
  bool has_unknown = false;
  {
    WriteLock lock(sub->mutex_);
    for (const auto& action : sub->actions_) {
      // Expect either a created event or attributes modified event.
      if (action == "CREATED" || action == "ATTRIBUTES_MODIFIED") {
        has_created = true;
      } else if (action == "UNKNOWN" || action == "") {
        // Allow an undetermined but existing FSevent on our target to pass.
        has_unknown = true;
      }
    }
  }
  EXPECT_TRUE(has_created || has_unknown);

  CreateEvents();
  sub->WaitForEvents(kMaxEventLatency, 2);
  bool has_updated = false;
  {
    WriteLock lock(sub->mutex_);
    // We may have triggered several updated events.
    for (const auto& action : sub->actions_) {
      if (action == "UPDATED") {
        has_updated = true;
      }
    }
  }
  EXPECT_TRUE(has_updated);

  EndEventLoop();
}
Ejemplo n.º 2
0
   void GameEventManagerTests::TestCopyConstructor()
   {
      CreateEvents(*mEventMgr);
      RefPtr<GameEventManager> copyGEM = new GameEventManager(*mEventMgr);

      CompareEventManagers(*mEventMgr, *copyGEM);
   }
Ejemplo n.º 3
0
TEST_F(FSEventsTests, test_fsevents_run) {
  // Assume event type is registered.
  event_pub_ = std::make_shared<FSEventsEventPublisher>();
  EventFactory::registerEventPublisher(event_pub_);

  // Create a subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  EventFactory::registerEventSubscriber(sub);

  // Create a subscriptioning context
  auto mc = std::make_shared<FSEventsSubscriptionContext>();
  mc->path = real_test_path;
  EventFactory::addSubscription(
      "fsevents", Subscription::create("TestFSEventsEventSubscriber", mc));
  event_pub_->configure();

  // Create an event loop thread (similar to main)
  temp_thread_ = std::thread(EventFactory::run, "fsevents");
  EXPECT_TRUE(event_pub_->numEvents() == 0);

  // Wait for the thread to start and the FSEvents stream to turn on.
  WaitForStream(kMaxEventLatency);

  // Cause an fsevents event(s) by writing to the watched path.
  CreateEvents();

  // Wait for the thread's run loop to select.
  WaitForEvents(kMaxEventLatency);

  EXPECT_TRUE(event_pub_->numEvents() > 0);

  // We are managing the thread ourselves, so no join needed.
  EventFactory::end(false);
  temp_thread_.join();
}
Ejemplo n.º 4
0
TEST_F(FSEventsTests, test_fsevents_run) {
  // Assume event type is registered.
  event_pub_ = std::make_shared<FSEventsEventPublisher>();
  EventFactory::registerEventPublisher(event_pub_);

  // Create a subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  EventFactory::registerEventSubscriber(sub);

  // Create a subscriptioning context
  auto mc = std::make_shared<FSEventsSubscriptionContext>();
  mc->path = kRealTestPath;
  EventFactory::addSubscription("fsevents", Subscription::create("TestFSEventsEventSubscriber", mc));

  // Create an event loop thread (similar to main)
  boost::thread temp_thread(EventFactory::run, "fsevents");
  EXPECT_TRUE(event_pub_->numEvents() == 0);

  // Cause an fsevents event(s) by writing to the watched path.
  CreateEvents();

  // Wait for the thread's run loop to select.
  WaitForEvents(kMaxEventLatency);

  EXPECT_TRUE(event_pub_->numEvents() > 0);
  EventFactory::end();
}
Ejemplo n.º 5
0
 void GameEventManagerTests::TestAssigmentOperator()
 {
    CreateEvents(*mEventMgr);
    RefPtr<GameEventManager> copyGEM = new GameEventManager();
    *copyGEM = *mEventMgr;
    
    CompareEventManagers(*mEventMgr, *copyGEM);
 }
Ejemplo n.º 6
0
void multiplex(period,normalize)
{
    // initialize sw thread to use BGPM in sw thread distributed mode
    // Allows up to 12 simultaineous punit counter per thread when using only
    // 2 threads/core
    Bgpm_Init(BGPM_MODE_SWDISTRIB);
  
    // Create event set and add events needed to calculate CPI,
    int hEvtSet = Bgpm_CreateEventSet();

    // Multiplexing must be enabled prior to adding events to a Punit event set.
    // With Multiplexing active on Punit event set, we can have as many Punit events as we like,
    // regardless of Max Events. Muxing will create as many groups as needed to hold all the events,
    // but by default only assigns up to 5 events per group (And reserves the 6th counter to track the number of
    // cycles a group has been active).
    // However, a few of the core-wide attributes used by events must still remain consistent
    // (like the l1p mode associated with the l1p events)
    //
    // Parameters:
    // period-> number of cycles between multiplex switches. A value of 0 disables multiplexing for this thread,
    //     which means you must explicitly call Bgpm_SwitchMux to switch between groups.
    // normalize->Pass in BGPM_NORMAL or BGPM_NOTNORMAL to choose whether event counts
    //     reported by Bgpm_ReadEvent() or Bgpm_ReadEventList() will be scaled to the to the maximum number of cycles spent
    //     by any mux group.
    //     With BGPM_NOTNORMAL, Bgpm_ReadEvent() and Bgpm_ReadEventList() report the raw numbers and you may use
    //     Bgpm_GetMultiplex() and Bgpm_GetMuxEventElapsedCycles() to do your own normalization as desired.
    Bgpm_SetMultiplex2(hEvtSet, period, normalize, BGPMMuxMinEvts);

    Bgpm_AddEventList(hEvtSet, evtList, sizeof(evtList)/sizeof(unsigned) );

    Bgpm_Apply(hEvtSet);
    Bgpm_Start(hEvtSet);

    const int loops = 100;
    int i; 
    for (i=0; i<loops; i++) {
        CreateEvents();
        if(!period){Bgpm_SwitchMux(hEvtSet);} // Switching mutiplex is needed only in case of period=0.
    }

    Bgpm_Stop(hEvtSet);
    PrintCounts(hEvtSet);
    Bgpm_Disable();
}
Ejemplo n.º 7
0
unsigned MFMediaIOEx::Read(void* pb,unsigned size)
{
	if (!CreateEvents())
		return 0;

	_dwReadOKSize = 0;
	_blockState = true;
	HRESULT hr = _pStream->BeginRead((BYTE*)pb,size,this,nullptr);
	if (FAILED(hr))
	{
		_blockState = false;
		return 0;
	}
	auto result = GetReadResult();
	_blockState = false;

	if (result != ReadOK || _dwReadOKSize == 0)
		return 0;
	return _dwReadOKSize;
}
Ejemplo n.º 8
0
TEST_F(FSEventsTests, test_fsevents_fire_event) {
  // Assume event type is registered.
  StartEventLoop();

  // Simulate registering an event subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  auto status = sub->init();

  // Create a subscriptioning context, note the added Event to the symbol
  auto sc = sub->GetSubscription(0);
  sub->subscribe(&TestFSEventsEventSubscriber::SimpleCallback, sc, nullptr);
  CreateEvents();

  // This time wait for the callback.
  sub->WaitForEvents(kMaxEventLatency, 1);

  // Make sure our expected event fired (aka subscription callback was called).
  EXPECT_TRUE(sub->callback_count_ > 0);
  EndEventLoop();
}
Ejemplo n.º 9
0
TEST_F(FSEventsTests, test_fsevents_event_action) {
  // Assume event type is registered.
  StartEventLoop();

  // Simulate registering an event subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  auto status = sub->init();

  auto sc = sub->GetSubscription(0);
  EventFactory::registerEventSubscriber(sub);
  sub->subscribe(&TestFSEventsEventSubscriber::Callback, sc, nullptr);
  CreateEvents();
  sub->WaitForEvents(kMaxEventLatency);

  // Make sure the fsevents action was expected.
  EXPECT_TRUE(sub->actions_.size() > 0);
  if (sub->actions_.size() > 1) {
    EXPECT_EQ(sub->actions_[0], "UPDATED");
  }
  EndEventLoop();
}
Ejemplo n.º 10
0
 void GameEventManagerTests::TestGetAllEvents()
 {
    try
    {
       CreateEvents(*mEventMgr);
 
       vector<GameEvent* > eventList;
       mEventMgr->GetAllEvents(eventList);
       for (unsigned i=0; i<25; i++)
       {
          GameEvent *found = mEventMgr->FindEvent(eventList[i]->GetUniqueId());
          CPPUNIT_ASSERT_MESSAGE("Could not search by unique id.",found != NULL);
          mEventMgr->RemoveEvent(eventList[i]->GetUniqueId());
       }
 
       CPPUNIT_ASSERT_MESSAGE("Should have 25 events in the manager.",mEventMgr->GetNumEvents() == 25);
       mEventMgr->ClearAllEvents();
       CPPUNIT_ASSERT_MESSAGE("Should have 0 events in the manager.",mEventMgr->GetNumEvents() == 0);
    }
    catch (const dtUtil::Exception& e)
    {
       CPPUNIT_FAIL(e.ToString());
    }
 }
Ejemplo n.º 11
0
void MusicEffect::Render(RenderBuffer &buffer,
    int bars, const std::string& type,
    int sensitivity, bool scale,
    const std::string& scalenotes, int offsetx,
    int startnote, int endnote,
    const std::string& colourtreatment,
    bool fade)
{
    // no point if we have no media
    if (buffer.GetMedia() == NULL)
    {
        return;
    }

    int nType = DecodeType(type);
    int nTreatment = DecodeColourTreatment(colourtreatment);
    int nScaleNotes = DecodeScaleNotes(scalenotes);

    // Grab our cache
    MusicRenderCache *cache = (MusicRenderCache*)buffer.infoCache[id];
    if (cache == nullptr) {
        cache = new MusicRenderCache();
        buffer.infoCache[id] = cache;
    }
    int &_bars = cache->_bars;
    int &_startNote = cache->_startNote;
    int &_endNote = cache->_endNote;
    int &_type = cache->_type;
    int &_offsetx = cache->_offsetx;
    bool &_scale = cache->_scale;
    int &_sensitivity = cache->_sensitivity;
    int &_scalenotes = cache->_scalenotes;
    bool &_fade = cache->_fade;
    int& _colourTreatment = cache->_colourTreatment;
    std::vector<std::list<MusicEvent*>*>& _events = cache->_events;

    int actualbars = std::min(bars, std::min(endnote - startnote + 1, buffer.BufferWi - offsetx));
    int notesperbar = (endnote - startnote + 1) / actualbars;
    int actualendnote = startnote + std::min(endnote, actualbars * notesperbar);
    int lightsperbar = 0.5 + (float)(buffer.BufferWi - offsetx) / (float)actualbars;

    // Check for config changes which require us to reset
    if (buffer.needToInit || _bars != bars || _type != nType || _startNote != startnote || 
        _endNote != endnote || _offsetx != offsetx || _scale != scale || 
        _scalenotes != nScaleNotes || _sensitivity != sensitivity || _colourTreatment != nTreatment || _fade != fade)
    {
        buffer.needToInit = false;
        _bars = bars;
        _fade = fade;
        _startNote = startnote;
        _endNote = endnote;
        _colourTreatment = nTreatment;
        _type = nType;
        _offsetx = offsetx;
        _scale = scale;
        _sensitivity = sensitivity;
        _scalenotes = nScaleNotes;
        cache->ClearEvents();
        // We limit bars to the width of the model less the x offset

        CreateEvents(buffer, _events, _startNote, actualendnote, actualbars, _scalenotes, _sensitivity);
    }

    int per = 1;
    if (_scale)
    {
        per = lightsperbar;
    }

    try
    {
        for (int x = 0; x < _events.size(); x++)
        {
            for (int i = 0; i < per; i++)
            {
                switch (_type)
                {
                case 1:
                    RenderMorph(buffer, (x*per) + i + _offsetx, _bars, _startNote, _endNote, *_events[x], _colourTreatment, false, fade);
                    break;
                case 2:
                    RenderMorph(buffer, (x*per) + i + _offsetx, _bars, _startNote, _endNote, *_events[x], _colourTreatment, true, fade);
                    break;
                case 3:
                    RenderCollide(buffer, (x*per) + i + _offsetx, _bars, _startNote, _endNote, true /* collide */, *_events[x], _colourTreatment, fade);
                    break;
                case 4:
                    RenderCollide(buffer, (x*per) + i + _offsetx, _bars, _startNote, _endNote, false /* uncollide */,* _events[x], _colourTreatment, fade);
                    break;
                case 5:
                    RenderOn(buffer, (x*per) + i + _offsetx, _bars, _startNote, _endNote, *_events[x], _colourTreatment, fade);
                    break;
                }
            }
        }
    }
    catch (...)
    {
        // This is here to let me catch any exceptions and stop the exception causing the render thread to die
        //int a = 0;
    }
}
Ejemplo n.º 12
0
ccsCOMPL_STAT wsf2ex1APPLICATION::Init(int argCount, char *arg[])
{
    wsf2libLOG_TRACE();
    ErrReset();


    // Turn off logging of warning on EXIT command
    evhTASK::LogExitWarning(FALSE);

    // Parses the command line arguments
    // and extract the configuration parameters
    // for ENV NAME, DB POINT and PROC NAME from the
    // command line or from the enviroment variables
    if (EvaluateArgs(argCount, arg, wsf2ex1DB_ROOT_POINT) == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_INIT, __FILE_LINE__, "wrong argument(s)");
	return FAILURE;
	}

    // Initialize CCS and connect to database
    if(InitCCS() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_INIT, __FILE_LINE__, "cannot init CCS");
	return FAILURE;      
	}

    // Logs current startup configuration
    eccsLOG_1(("%s - Application started (proc name: %s, DB root point: %s)", 
	       GetProcName(), GetProcName(), GetDbRoot()));
    logData(wsf2ex1MOD,"%s - Application started (proc name: %s, DB root point: %s)", 
	    GetProcName(), GetProcName(), GetDbRoot());

   /*
    * Create factory for ACTIONS, DATA, CONFIG and CONTROL
    */
    wsf2libASSERT(mActionMgr == NULL);
    mActionMgr = new wsf2ex1ACTION_MGR(GetDbRoot(), argCount, arg, GetEventMgr());
    if (mActionMgr == NULL)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "no memory for allocating wsf2ex1ACTION_MGR");
	return FAILURE;
	}
    if (wsf2libHELPER::ObjectOk(mActionMgr, "ACTION_MGR") == ccsFALSE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_CREATE, __FILE_LINE__, "wsf2ex1ACTION_MGR");
	return FAILURE;	
	}

    /*
     * Set FSM context
     * TBD: rename method
     */
    SetControl(mActionMgr->GetControl());

    /*
     * Instantiate events and actions
     */
    if (CreateEvents(wsf2ex1EVENTS_FILENAME) == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_CREATE, __FILE_LINE__, "Events");
	return FAILURE;	
	}
    if (mActionMgr->CreateActions() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_CREATE, __FILE_LINE__, "Actions");
	return FAILURE;	
	}
    /*
     * Load SCXML Model
     */
    if (LoadModel(wsf2ex1MODEL_FILENAME, mActionMgr->SCXMLGetActions(), mActionMgr->SCXMLGetActivities()) == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "cannot load SCXML model");
	return FAILURE;
	}

    /*
     * Initialize all events and actions and data structures
     */
    if (mActionMgr->Init() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "initializing actions and data structures");
	return FAILURE;
	}

    /*
     * Start the execution of SCXML model
     */
    if (StartModel() == FAILURE)
	{
	errAdd(wsf2ex1MOD, wsf2ex1ERR_FATAL, __FILE_LINE__, "cannot start SCXML model execution");
	return FAILURE;
	}

    return SUCCESS;
}