Skip to content

Commit

Permalink
Merge remote-tracking branch 'gec/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Verges committed Jul 15, 2011
2 parents e3ba35d + 2fc533f commit df350a9
Show file tree
Hide file tree
Showing 62 changed files with 986 additions and 415 deletions.
24 changes: 20 additions & 4 deletions APL/APL.vcproj
Expand Up @@ -540,6 +540,10 @@
RelativePath=".\Configure.h"
>
</File>
<File
RelativePath=".\DeleteAny.h"
>
</File>
<File
RelativePath=".\Exception.cpp"
>
Expand All @@ -548,6 +552,10 @@
RelativePath=".\Exception.h"
>
</File>
<File
RelativePath=".\GetKeys.h"
>
</File>
<File
RelativePath=".\Parsing.cpp"
>
Expand Down Expand Up @@ -732,6 +740,18 @@
<Filter
Name="Timers"
>
<File
RelativePath=".\ITimer.h"
>
</File>
<File
RelativePath=".\ITimerSource.cpp"
>
</File>
<File
RelativePath=".\ITimerSource.h"
>
</File>
<File
RelativePath=".\PostingNotifier.cpp"
>
Expand Down Expand Up @@ -764,10 +784,6 @@
RelativePath=".\TimerASIO.h"
>
</File>
<File
RelativePath=".\TimerInterfaces.h"
>
</File>
<File
RelativePath=".\TimerSourceASIO.cpp"
>
Expand Down
2 changes: 1 addition & 1 deletion APL/AsyncTaskBase.cpp
Expand Up @@ -170,7 +170,7 @@ bool AsyncTaskBase::LessThanGroupLevelNoString(const AsyncTaskBase* l, const Asy
}

bool AsyncTaskBase::LessThanGroupLevel(const AsyncTaskBase* l, const AsyncTaskBase* r)
{
{
return LessThanGroupLevelNoString(l, r);
}

Expand Down
56 changes: 33 additions & 23 deletions APL/AsyncTaskGroup.cpp
Expand Up @@ -25,7 +25,7 @@
#include "AsyncTaskScheduler.h"
#include "Exception.h"

#include "TimerInterfaces.h"
#include "ITimerSource.h"

#include <boost/foreach.hpp>
#include <boost/bind.hpp>
Expand All @@ -37,6 +37,7 @@ namespace apl

AsyncTaskGroup::AsyncTaskGroup(ITimerSource* apTimerSrc, ITimeSource* apTimeSrc) :
mIsRunning(false),
mShutdown(false),
mpTimerSrc(apTimerSrc),
mpTimeSrc(apTimeSrc),
mpTimer(NULL)
Expand All @@ -46,14 +47,11 @@ AsyncTaskGroup::AsyncTaskGroup(ITimerSource* apTimerSrc, ITimeSource* apTimeSrc)

AsyncTaskGroup::~AsyncTaskGroup()
{
if(mpTimer) {
mpTimer->Cancel();
mpTimer = NULL;
}
this->Shutdown();

BOOST_FOREACH(AsyncTaskBase* p, mTaskVec) {
BOOST_FOREACH(AsyncTaskBase * p, mTaskVec) {
delete p;
}
}
}

AsyncTaskBase* AsyncTaskGroup::Add(millis_t aPeriod, millis_t aRetryDelay, int aPriority, const TaskHandler& arCallback, const std::string& arName)
Expand All @@ -70,7 +68,7 @@ AsyncTaskBase* AsyncTaskGroup::Add(millis_t aPeriod, millis_t aRetryDelay, int a

void AsyncTaskGroup::ResetTasks(int aMask)
{
BOOST_FOREACH(AsyncTaskBase* p, mTaskVec) {
BOOST_FOREACH(AsyncTaskBase * p, mTaskVec) {
if(!p->IsRunning() && (p->GetFlags() & aMask)) p->Reset();
}
}
Expand All @@ -94,33 +92,43 @@ void AsyncTaskGroup::Remove(AsyncTaskBase* apTask)
throw ArgumentException(LOCATION, "Task not found");
}

void AsyncTaskGroup::Shutdown()
{
if(mpTimer) {
mpTimer->Cancel();
mpTimer = NULL;
}

mShutdown = true;
}

void AsyncTaskGroup::Enable()
{
BOOST_FOREACH(AsyncTaskBase* p, mTaskVec) {
BOOST_FOREACH(AsyncTaskBase * p, mTaskVec) {
p->SilentEnable();
}
this->CheckState();
}

void AsyncTaskGroup::Disable()
{
BOOST_FOREACH(AsyncTaskBase* p, mTaskVec) {
BOOST_FOREACH(AsyncTaskBase * p, mTaskVec) {
p->SilentDisable();
}
this->CheckState();
}

void AsyncTaskGroup::Enable(int aMask)
{
BOOST_FOREACH(AsyncTaskBase* p, mTaskVec) {
BOOST_FOREACH(AsyncTaskBase * p, mTaskVec) {
if((p->GetFlags() & aMask) != 0) p->SilentEnable();
}
this->CheckState();
}

void AsyncTaskGroup::Disable(int aMask)
{
BOOST_FOREACH(AsyncTaskBase* p, mTaskVec) {
BOOST_FOREACH(AsyncTaskBase * p, mTaskVec) {
if((p->GetFlags() & aMask) != 0) p->SilentDisable();
}
this->CheckState();
Expand All @@ -142,18 +150,20 @@ AsyncTaskBase* AsyncTaskGroup::GetNext(const boost::posix_time::ptime& arTime)

void AsyncTaskGroup::CheckState()
{
ptime now = GetUTC();
AsyncTaskBase* pTask = GetNext(now);
if(!mShutdown) {
ptime now = GetUTC();
AsyncTaskBase* pTask = GetNext(now);

if(pTask == NULL) return;
if(pTask->NextRunTime() == max_date_time) return;
if(pTask == NULL) return;
if(pTask->NextRunTime() == max_date_time) return;

if(pTask->NextRunTime() <= now) {
mIsRunning = true;
pTask->Dispatch();
}
else {
this->RestartTimer(pTask->NextRunTime());
if(pTask->NextRunTime() <= now) {
mIsRunning = true;
pTask->Dispatch();
}
else {
this->RestartTimer(pTask->NextRunTime());
}
}
}

Expand All @@ -171,7 +181,7 @@ boost::posix_time::ptime AsyncTaskGroup::GetUTC() const

void AsyncTaskGroup::Update(const boost::posix_time::ptime& arTime)
{
BOOST_FOREACH(AsyncTaskBase* p, mTaskVec) {
BOOST_FOREACH(AsyncTaskBase * p, mTaskVec) {
p->UpdateTime(arTime);
}
}
Expand Down
3 changes: 3 additions & 0 deletions APL/AsyncTaskGroup.h
Expand Up @@ -57,6 +57,8 @@ class AsyncTaskGroup : private Uncopyable
AsyncTaskContinuous* AddContinuous(int aPriority, const TaskHandler& arCallback, const std::string& arName = "");
void Remove(AsyncTaskBase* apTask);

void Shutdown();

void Enable();
void Disable();

Expand All @@ -82,6 +84,7 @@ class AsyncTaskGroup : private Uncopyable
AsyncTaskBase* GetNext(const boost::posix_time::ptime& arTime);

bool mIsRunning;
bool mShutdown;
ITimerSource* mpTimerSrc;
ITimeSource* mpTimeSrc;
ITimer* mpTimer;
Expand Down
2 changes: 1 addition & 1 deletion APL/DataTypes.h
Expand Up @@ -33,8 +33,8 @@ class Binary : public BoolDataPoint
{
public:
Binary(bool aValue, boost::uint8_t aQuality = BQ_RESTART) : BoolDataPoint(BQ_RESTART, DT_BINARY, BQ_STATE) {
SetValue(aValue);
SetQuality(aQuality);
SetValue(aValue);
}
Binary() : BoolDataPoint(BQ_RESTART, DT_BINARY, BQ_STATE) {}

Expand Down
38 changes: 38 additions & 0 deletions APL/DeleteAny.h
@@ -0,0 +1,38 @@
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Green Enery Corp licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

#ifndef __DELETE_ANY_H_
#define __DELETE_ANY_H_

#include <vector>

namespace apl
{

/** Useful for posting to a timer source */
template <class T>
void DeleteAny(const T* apType)
{
delete apType;
}

}

#endif

14 changes: 7 additions & 7 deletions APL/FlexibleDataObserver.h
Expand Up @@ -19,7 +19,6 @@
#ifndef __FLEXIBLE_DATA_OBSERVER_H_
#define __FLEXIBLE_DATA_OBSERVER_H_


#include "DataInterfaces.h"
#include "Lock.h"
#include "SubjectBase.h"
Expand All @@ -30,6 +29,12 @@

namespace apl
{

template <typename T>
struct PointMap {
typedef std::map<size_t, T> Type;
};

/** Simple data obsever that stores the current value of anything it receives. SubjectBase implictly
notifies observers of any updates.
Expand All @@ -41,11 +46,6 @@ class FlexibleDataObserver : public apl::IDataObserver, public SubjectBase<SigLo

FlexibleDataObserver();

template <typename T>
struct PointMap {
typedef std::map<size_t, T> Type;
};

// allow direct access to the maps
PointMap<Binary>::Type mBinaryMap;
PointMap<Analog>::Type mAnalogMap;
Expand Down Expand Up @@ -256,7 +256,7 @@ template <class T>
void FlexibleDataObserver::Print(typename PointMap<T>::Type& arMap)
{
int j = 0;
typename FlexibleDataObserver::PointMap<T>::Type::iterator i = arMap.begin();
typename PointMap<T>::Type::iterator i = arMap.begin();
for(; i != arMap.end(); ++i) {
std::cout << j << ", " << i->second.GetValue() << ", " << static_cast<int>(i->second.GetQuality()) << std::endl;
++j;
Expand Down
41 changes: 41 additions & 0 deletions APL/GetKeys.h
@@ -0,0 +1,41 @@
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Green Enery Corp licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

#ifndef __KEY_KEYS_H_
#define __KEY_KEYS_H_

#include <vector>

namespace apl
{

template <class T, class U>
static std::vector<U> GetKeys(const T& arMap)
{
std::vector<U> ret;
for(typename T::const_iterator i = arMap.begin(); i != arMap.end(); ++i) {
ret.push_back(i->first);
}
return ret;
}

}

#endif

52 changes: 52 additions & 0 deletions APL/ITimer.h
@@ -0,0 +1,52 @@
//
// Licensed to Green Energy Corp (www.greenenergycorp.com) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Green Enery Corp licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
#ifndef __I_TIMER_H_
#define __I_TIMER_H_

#include <boost/date_time/posix_time/posix_time_types.hpp>

namespace apl
{

/**
* This is a wrapper for ASIO timers that are used to post events
* on a queue. Events can be posted for immediate consumption or
* some time in the future. Events can be consumbed by the posting
* thread or another thread.
*
* @section Class Goals
*
* Decouple APL code form ASIO so ASIO could be replace if need be.
*
* There is a problem with ASIO. When cancel is called, an event is
* posted. We wanted a cancel that does not generate any events.
*
* @see TimerASIO
*/
class ITimer
{
public:
virtual ~ITimer() {}
virtual void Cancel() = 0;
virtual boost::posix_time::ptime ExpiresAt() = 0;
};

}

#endif

0 comments on commit df350a9

Please sign in to comment.