source: proiecte/SIMEO/Simeo/src/SimeoEngine/Agent.cpp @ 167

Last change on this file since 167 was 167, checked in by (none), 14 years ago

Simeo: added final project and also older proof of concept code.

We used Git for version control, so look at the Git repo
in SIMEO/Simeo/ for more info.

File size: 1.0 KB
Line 
1#include <stdio.h>
2#include "Agent.h"
3
4
5Agent::Agent(vector<Sensor *> sensorList, vector<Actuator *> actuatorList, vector<CommChannel *> channelList)
6{
7        m_sensorList = sensorList;
8        m_actuatorList = actuatorList;
9        m_channelList = channelList;
10}
11
12Agent::~Agent()
13{
14        int i;
15
16        for (i = 0; i < (int) m_sensorList.size(); i++) {
17                delete m_sensorList[i];
18        }
19
20        for (i = 0; i < (int) m_actuatorList.size(); i++) {
21                delete m_actuatorList[i];
22        }
23
24        for (i = 0; i < (int) m_channelList.size(); i++) {
25                delete m_channelList[i];
26        }
27}
28
29void Agent::run()
30{
31        int i;
32        int rank, stop = 0;
33        MPI_Status status;
34
35        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
36
37        while (!stop) {
38                MPI_Recv(&stop, 1, MPI_INT, MASTER_ID, SYNC_MSG, MPI_COMM_WORLD, &status);
39
40                for (i = 0; i < (int) m_sensorList.size(); i++) {
41                        Sensor *x = m_sensorList[i];
42                        x->update();
43                }
44
45                step();
46
47                for (i = 0; i < (int) m_actuatorList.size(); i++) {
48                        Actuator *x = m_actuatorList[i];
49                        x->update();
50                }
51
52                MPI_Send(&stop, 1, MPI_INT, MASTER_ID, SYNC_MSG, MPI_COMM_WORLD);
53        }
54}
Note: See TracBrowser for help on using the repository browser.