trunk: backport eventing from 1.4.3

This commit is contained in:
Marian Krivos
2012-02-05 12:16:58 +00:00
parent 59fe68edbe
commit 7d7c02c579
412 changed files with 3564 additions and 3634 deletions

View File

@@ -1,7 +1,7 @@
//
// FunctionPriorityDelegate.h
//
// $Id: //poco/svn/Foundation/include/Poco/FunctionPriorityDelegate.h#2 $
// $Id: //poco/1.4/Foundation/include/Poco/FunctionPriorityDelegate.h#5 $
//
// Library: Foundation
// Package: Events
@@ -9,7 +9,7 @@
//
// Implementation of the FunctionPriorityDelegate template.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
@@ -36,12 +36,13 @@
//
#ifndef Foundation_FunctionPriorityDelegate_INCLUDED
#define Foundation_FunctionPriorityDelegate_INCLUDED
#ifndef Foundation_FunctionPriorityDelegate_INCLUDED
#define Foundation_FunctionPriorityDelegate_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/AbstractPriorityDelegate.h"
#include "Poco/Mutex.h"
namespace Poco {
@@ -49,23 +50,23 @@ namespace Poco {
template <class TArgs, bool useSender = true, bool senderIsConst = true>
class FunctionPriorityDelegate: public AbstractPriorityDelegate<TArgs>
/// Wraps a C style function (or a C++ static fucntion) to be used as
/// a priority delegate
/// Wraps a freestanding function or static member function
/// for use as a PriorityDelegate.
{
public:
typedef void (*NotifyMethod)(const void*, TArgs&);
typedef void (*NotifyMethod)(const void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
_receiverMethod(delegate._receiverMethod)
{
}
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod)
{
}
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
{
@@ -82,22 +83,40 @@ public:
{
}
bool notify(const void* sender, TArgs& arguments)
{
(*_receiverMethod)(sender, arguments);
return true; // per default the delegate never expires
}
bool notify(const void* sender, TArgs& arguments)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
{
(*_receiverMethod)(sender, arguments);
return true;
}
else return false;
}
AbstractPriorityDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyMethod _receiverMethod;
Mutex _mutex;
private:
FunctionPriorityDelegate();
FunctionPriorityDelegate();
};
@@ -105,19 +124,19 @@ template <class TArgs>
class FunctionPriorityDelegate<TArgs, true, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(void*, TArgs&);
typedef void (*NotifyMethod)(void*, TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
_receiverMethod(delegate._receiverMethod)
{
}
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod)
{
}
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
{
@@ -134,43 +153,60 @@ public:
{
}
bool notify(const void* sender, TArgs& arguments)
{
(*_receiverMethod)(const_cast<void*>(sender), arguments);
return true; // per default the delegate never expires
}
bool notify(const void* sender, TArgs& arguments)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
{
(*_receiverMethod)(const_cast<void*>(sender), arguments);
return true;
}
else return false;
}
AbstractPriorityDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyMethod _receiverMethod;
Mutex _mutex;
private:
FunctionPriorityDelegate();
FunctionPriorityDelegate();
};
template <class TArgs>
class FunctionPriorityDelegate<TArgs, false>: public AbstractPriorityDelegate<TArgs>
{
public:
typedef void (*NotifyMethod)(TArgs&);
typedef void (*NotifyMethod)(TArgs&);
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(*reinterpret_cast<void**>(&method), prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate._pTarget, delegate._priority),
_receiverMethod(delegate._receiverMethod)
{
}
FunctionPriorityDelegate(NotifyMethod method, int prio):
AbstractPriorityDelegate<TArgs>(prio),
_receiverMethod(method)
{
}
FunctionPriorityDelegate(const FunctionPriorityDelegate& delegate):
AbstractPriorityDelegate<TArgs>(delegate),
_receiverMethod(delegate._receiverMethod)
{
}
FunctionPriorityDelegate& operator = (const FunctionPriorityDelegate& delegate)
{
@@ -187,26 +223,44 @@ public:
{
}
bool notify(const void* sender, TArgs& arguments)
{
(*_receiverMethod)(arguments);
return true; // per default the delegate never expires
}
bool notify(const void* sender, TArgs& arguments)
{
Mutex::ScopedLock lock(_mutex);
if (_receiverMethod)
{
(*_receiverMethod)(arguments);
return true;
}
else return false;
}
AbstractPriorityDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
bool equals(const AbstractDelegate<TArgs>& other) const
{
const FunctionPriorityDelegate* pOtherDelegate = dynamic_cast<const FunctionPriorityDelegate*>(other.unwrap());
return pOtherDelegate && this->priority() == pOtherDelegate->priority() && _receiverMethod == pOtherDelegate->_receiverMethod;
}
AbstractDelegate<TArgs>* clone() const
{
return new FunctionPriorityDelegate(*this);
}
void disable()
{
Mutex::ScopedLock lock(_mutex);
_receiverMethod = 0;
}
protected:
NotifyMethod _receiverMethod;
NotifyMethod _receiverMethod;
Mutex _mutex;
private:
FunctionPriorityDelegate();
FunctionPriorityDelegate();
};
} // namespace Poco
#endif
#endif // Foundation_FunctionPriorityDelegate_INCLUDED