summaryrefslogtreecommitdiff
path: root/src/programchain.cpp
blob: 1d005e29c7a0895b937bffaec9b4aa77c14f29ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include <stdlib.h>
#include "bu/programchain.h"
#include "bu/programlink.h"

using namespace Bu;

Bu::ProgramChain::ProgramChain()
{
}

Bu::ProgramChain::~ProgramChain()
{
}

bool Bu::ProgramChain::addLink( ProgramLink *pLink )
{
	if( pLink->init() == false )
	{
		emergencyShutdown();
		return false;
	}

	lLink.append( pLink );

	pLink->setChain( this );

	return true;
}

ProgramLink *Bu::ProgramChain::getLink( const char *lpName )
{
	char a;
	a = lpName[0];
	return NULL;
}

ProgramLink *Bu::ProgramChain::getBaseLink()
{
	return NULL;
}

bool Bu::ProgramChain::execChainOnce()
{
	for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin();
		 i != lLink.end(); i++ )
	{
		if( (*i)->timeSlice() == false )
		{
			emergencyShutdown();
			return false;
		}
	}

	return true;
}

bool Bu::ProgramChain::enterChainLoop()
{
	for(;;)
	{
		if( execChainOnce() == false )
		{
			return false;
		}
	}

	return true;
}

void Bu::ProgramChain::emergencyShutdown()
{
	for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin();
		 i != lLink.end(); i++ )
	{
		(*i)->deInit();
		delete *i;
	}
	lLink.clear();
}

LinkMessage *Bu::ProgramChain::broadcastIRM( LinkMessage *pMsgOut, ProgramLink * /*pSender*/ )
{
	for( Bu::List<Bu::ProgramLink *>::iterator i = lLink.begin();
		 i != lLink.end(); i++ )
	{
		LinkMessage *pMsg = (*i)->processIRM( pMsgOut );
		if( pMsg != NULL )
		{
			delete pMsgOut;
			return pMsg;
		}
	}

	delete pMsgOut;
	return NULL;
}