PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PEventLoop-es.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"
36
37
38class PDevice;
39class PList;
40class PNode;
41class PEventQueue;
42
45
47{
48public:
49
50 PEventLoop();
52
53 //One way to use the event loop is to register condition states of devices. The
54 //loop then examines the devices on each loop, determining if the device is
55 //in some certain state. These methods add and remove such states.
56 void RegisterState(DeviceState * state,
57 const std::string & function,
58 Variant parameters);
59
60 void RegisterEvent(DeviceState * state,
61 const std::string & function,
62 Variant parameters);
64
65 //Another way to use the event loop is to register conditions associated with 'events'
66 //that arrive through the event queue. On each iteration, the event loop tests all such
67 //event tests against the top event in the queue
68
69 //The queue needs to be defined at the platform level, but it is a subclassed PDevice, and
70 //so is carried along with the DeviceState test.
71 void RegisterEventTest(DeviceState * state, const std::string function, PList * parameters);
73
74 //Clears all state/events tests.
75 void Clear();
76
78 PEvent Loop();
79
80
82 PEvent Loop1();
83
84 //Overload of the << operator
85 friend std::ostream & operator <<(std::ostream & out, const PEventLoop & loop );
86
87 std::string mTmp; //temporary string.
88 bool IsLooping(){return mIsLooping;}
89
90protected:
91
92
93 //These structures keep track of normal states with corresponding
94 //function nodes and parameters to execute when true.
95 std::vector<DeviceState*> mStates;
96 std::vector<PNode *> mNodes;
97 std::vector<Variant> mFunctionNames; //Function names for scope setup
99
100 std::vector<Variant> mParameters;
101
102
103 //The following structure keep track of whether the
104 //state is a 'normal' device query test (false) or
105 //a special event-queue test (true.)
106 std::vector<bool> mIsEvent;
107
108private:
109 bool mIsLooping; //allows for reentrant loop. Currently, not used because we look at gKeepLooping.
110 bool mCallbackScheduled; //Flag indicating Loop1() scheduled a callback for Loop() to execute
111 size_t mCallbackNodeStackSize; //Node stack size before scheduling callback (for execution tracking)
112
113};
114
115
116
117#endif
std::vector< Variant > mParameters
void RemoveState(DeviceState state)
void RemoveEventTest(DeviceState state)
friend std::ostream & operator<<(std::ostream &out, const PEventLoop &loop)
std::string mTmp
std::vector< bool > mIsEvent
std::vector< PNode * > mNodes
PEvent Loop()
Initiates the looping tests.
PEvent Loop1()
Initiates the looping tests.
bool IsLooping()
void RegisterEvent(DeviceState *state, const std::string &function, Variant parameters)
void RegisterEventTest(DeviceState *state, const std::string function, PList *parameters)
void RegisterState(DeviceState *state, const std::string &function, Variant parameters)
~PEventLoop()
This is the standard pNode destructor.
std::vector< Variant > mFunctionNames
PEventLoop()
This is the standard PEventLoop constructor.
std::vector< DeviceState * > mStates
Definition PList.h:45
Definition PNode.h:45