poco/WebWidgets/include/Poco/WebWidgets/JavaScriptEvent.h
2007-07-02 10:48:36 +00:00

117 lines
3.7 KiB
C++

//
// JavaScriptEvent.h
//
// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/JavaScriptEvent.h#5 $
//
// Library: WebWidgets
// Package: WebEvents
// Module: JavaScriptEvent
//
// Definition of the JavaScriptEvent class.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef WebWidgets_JavaScriptEvent_INCLUDED
#define WebWidgets_JavaScriptEvent_INCLUDED
#include "Poco/WebWidgets/WebWidgets.h"
#include "Poco/WebWidgets/JSDelegate.h"
#include "Poco/AbstractEvent.h"
#include "Poco/DefaultStrategy.h"
#include "Poco/AbstractDelegate.h"
#include "Poco/CompareFunctions.h"
namespace Poco {
namespace WebWidgets {
template <class TArgs>
class WebWidgets_API JavaScriptEvent: public Poco::AbstractEvent <
TArgs, Poco::DefaultStrategy<TArgs, Poco::AbstractDelegate<TArgs>, Poco::p_less<Poco::AbstractDelegate<TArgs> > >,
Poco::AbstractDelegate<TArgs>
>
/// Event class used to handle JavaScriptEvents. Allows to register two different types
/// of delegates. The standard delegates, as known from Poco::BasicEvent and JSDelegates
/// which will be embedded into the WebPage when the Parser generates the site.
{
public:
JavaScriptEvent()
/// Creates the JavaScriptEvent.
{
}
~JavaScriptEvent()
/// Destroys the JavaScriptEvent.
{
}
bool hasLocalHandlers () const
{
FastMutex::ScopedLock lock(this->_mutex);
return !this->_strategy.empty();
}
bool hasJavaScriptHandlers() const
{
FastMutex::ScopedLock lock(this->_mutex);
return !_jsHandlers.empty();
}
void add (const JSDelegate& aDelegate)
/// Adds a javascript delegate to the event.
{
FastMutex::ScopedLock lock(this->_mutex);
_jsHandlers.insert(aDelegate);
}
void remove (const JSDelegate& aDelegate)
/// Removes a javascript delegate from the event. If the delegate is equal to an
/// already existing one is determined by the < operator.
/// If the observer is not found, the unregister will be ignored
{
FastMutex::ScopedLock lock(this->_mutex);
_jsHandlers.erase(aDelegate);
}
const std::set<JSDelegate>& jsDelegates() const
/// Returns all delegates currently registered
{
return _jsHandlers;
}
private:
std::set<JSDelegate> _jsHandlers;
};
} } // namespace Poco::WebWidgets
#endif // WebWidgets_JavaScriptEvent_INCLUDED