PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PEventLoop.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/devices/PEventLoop.h
4// Purpose: Primary Event Loop.
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PEVENTLOOP_H__
28#define __PEVENTLOOP_H__
29
30#include <iostream>
31#include <vector>
32#include "DeviceState.h"
33#include "PEvent.h"
34#include "../utility/rc_ptrs.h"
35#include "../base/PEBLObject.h"
36class PDevice;
37class PList;
38class PNode;
39class PEventQueue;
40
43
44class PEventLoop
45{
46public:
47
50
51 //One way to use the event loop is to register condition states of devices. The
52 //loop then examines the devices on each loop, determining if the device is
53 //in some certain state. These methods add and remove such states.
55 const std::string & function,
56 Variant parameters);
58 const std::string & function,
59 Variant parameters);
61
62 //Another way to use the event loop is to register conditions associated with 'events'
63 //that arrive through the event queue. On each iteration, the event loop tests all such
64 //event tests against the top event in the queue
65
66 //The queue needs to be defined at the platform level, but it is a subclassed PDevice, and
67 //so is carried along with the DeviceState test.
68 void RegisterEventTest(DeviceState * state, const std::string function, PList * parameters);
70
71 //Clears all state/events tests.
72 void Clear();
73
76
77 //Overload of the << operator
78 friend std::ostream & operator <<(std::ostream & out, const PEventLoop & loop );
79 void Print(std::ostream & out)const;
80
81protected:
82
83 //These structures keep track of normal states with corresponding
84 //function nodes and parameters to execute when true.
85 std::vector<DeviceState*> mStates;
86 std::vector<PNode *> mNodes;
87 std::vector<Variant> mParameters;
88
89 //The following structure keep track of whether the
90 //state is a 'normal' device query test (false) or
91 //a special event-queue test (true.)
92 std::vector<bool> mIsEvent;
93private:
94
95};
96
97
98
99#endif
std::vector< Variant > mParameters
void RemoveState(DeviceState state)
void RemoveEventTest(DeviceState state)
friend std::ostream & operator<<(std::ostream &out, const PEventLoop &loop)
std::vector< bool > mIsEvent
void Clear()
std::vector< PNode * > mNodes
PEvent Loop()
Initiates the looping tests.
void RegisterEvent(DeviceState *state, const std::string &function, Variant parameters)
void Print(std::ostream &out) const
void RegisterEventTest(DeviceState *state, const std::string function, PList *parameters)
void RegisterState(DeviceState *state, const std::string &function, Variant parameters)
std::vector< DeviceState * > mStates
Definition PList.h:45
Definition PNode.h:45