/usr/include/xmms2/xmmsclient/xmmsclient++/signal.h is in libxmmsclient++-dev 0.8+dfsg-18.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | /* XMMS2 - X Music Multiplexer System
* Copyright (C) 2003-2011 XMMS2 Team
*
* PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#ifndef XMMSCLIENTPP_SIGNAL_H
#define XMMSCLIENTPP_SIGNAL_H
#include <xmmsclient/xmmsclient.h>
#include <xmmsclient/xmmsclient++/exceptions.h>
#include <boost/function.hpp>
#include <string>
#include <list>
#include <iostream>
#include <deque>
#include <boost/scoped_ptr.hpp>
namespace Xmms
{
/** @cond INTERNAL */
namespace Coll {
class Coll;
}
/** @class SignalInterface
* This is here only to unify all Signal classes so that they can be
* put in one list.
*/
struct SignalInterface
{
typedef std::deque< boost::function< bool( const std::string& ) > > error_sig;
public:
SignalInterface() {}
virtual ~SignalInterface() {}
};
/** @class Signal
* Holds error signal and normal signal
*/
template< typename T >
struct Signal : public SignalInterface
{
typedef std::deque< boost::function< bool( T& ) > > signal_t;
error_sig error_signal;
signal_t signal;
};
/** @class Signal
* Specialized Signal for void signals.
*/
template<>
struct Signal< void > : public SignalInterface
{
typedef std::deque< boost::function< bool() > > signal_t;
error_sig error_signal;
signal_t signal;
};
/** @class SignalHolder
* @brief Holds a list of Signal classes and deletes them when requested
* or when the program quits and there still are some in the list.
* @note A singleton.
*/
class Client;
class SignalHolder
{
public:
/** Get the instance of this class.
* @return a SignalHolder instance.
*/
static SignalHolder& getInstance();
/** Add a signal to the list.
* @param sig A pointer to signal to add.
* @note You must @b not delete the signal afterwards.
*/
void addSignal( SignalInterface* sig );
/** Remove a signal from the list.
* @param sig A pointer to signal to remove.
* @note This will delete the signal too.
*/
void removeSignal( SignalInterface* sig );
/** Cleans up existing signals
*/
~SignalHolder();
/** @cond */
private:
friend class Client;
SignalHolder()
{
}
SignalHolder( SignalHolder& src );
SignalHolder& operator=( SignalHolder& src );
void deleteAll();
std::list< SignalInterface* > signals_;
/** @endcond */
};
/** Templated functions for extracting the correct value from
* xmmsv_t.
* @note return value must be deleted
*/
template< typename T >
inline T* extract_value( xmmsv_t* val )
{
return new T( val );
}
template<>
inline int*
extract_value( xmmsv_t* val )
{
int* temp = new int;
xmmsv_get_int( val, temp );
return temp;
}
template<>
inline std::basic_string<unsigned char>*
extract_value( xmmsv_t* val )
{
const unsigned char* temp = 0;
unsigned int len = 0;
xmmsv_get_bin( val, &temp, &len );
return new std::basic_string<unsigned char>( temp, len );
}
template<>
inline std::string*
extract_value( xmmsv_t* val )
{
const char* temp = 0;
xmmsv_get_string( val, &temp );
return new std::string( temp );
}
template<>
inline xmms_playback_status_t*
extract_value( xmmsv_t* val )
{
int32_t temp = 0;
xmmsv_get_int( val, &temp );
xmms_playback_status_t* result = new xmms_playback_status_t;
*result = static_cast< xmms_playback_status_t >( temp );
return result;
}
template<>
inline xmms_mediainfo_reader_status_t*
extract_value( xmmsv_t* val )
{
int temp = 0;
xmmsv_get_int( val, &temp );
xmms_mediainfo_reader_status_t* result
= new xmms_mediainfo_reader_status_t;
*result = static_cast< xmms_mediainfo_reader_status_t >( temp );
return result;
}
Coll::Coll*
extract_collection( xmmsv_t* val );
template<>
inline Coll::Coll*
extract_value( xmmsv_t* val )
{
return extract_collection( val );
}
/** Templated function to handle the value extraction, signal calling
* and deletion of the extracted value.
*/
template< typename T >
inline bool
callSignal( const Signal< T >* sig, xmmsv_t*& val )
{
boost::scoped_ptr< T > value( extract_value< T >( val ) );
bool ret = true;
for( typename Signal<T>::signal_t::const_iterator i = sig->signal.begin();
i != sig->signal.end(); ++i )
{
ret &= (*i)(*value);
}
return ret;
}
/** Specialized version of the templated callSignal.
*/
template<>
inline bool
callSignal( const Signal< void >* sig, xmmsv_t*& /* val */)
{
bool ret = true;
for( Signal<void>::signal_t::const_iterator i = sig->signal.begin();
i != sig->signal.end(); ++i )
{
ret &= (*i)();
}
return ret;
}
inline bool
callError( const SignalInterface::error_sig& error_signal,
const std::string& error )
{
bool ret = true;
for( SignalInterface::error_sig::const_iterator i = error_signal.begin();
i != error_signal.end(); ++i )
{
ret &= (*i)( error );
}
return ret;
}
/** Called on the notifier udata when an xmmsc_result_t is freed.
*/
inline void
freeSignal( void* notifier_data )
{
SignalInterface *sig = static_cast< SignalInterface* >( notifier_data );
SignalHolder::getInstance().removeSignal( sig );
}
/** Generic callback function to handle signal calling, error checking,
* signal renewing, broadcast disconnection and Signal deletion.
*/
template< typename T >
inline int
generic_callback( xmmsv_t* val, void* userdata )
{
if( !userdata ) {
return 0; // don't restart
}
Signal< T >* data = static_cast< Signal< T >* >( userdata );
bool ret = false;
if( xmmsv_is_error( val ) ) {
const char *buf;
xmmsv_get_error( val, &buf );
std::string error( buf );
if( !data->error_signal.empty() ) {
ret = callError(data->error_signal, error);
}
}
else {
if( !data->signal.empty() ) {
try {
ret = callSignal( data, val );
}
catch( exception& e ) {
std::exception* ee = 0;
if( (ee = dynamic_cast<std::exception*>( &e )) &&
!data->error_signal.empty() ) {
ret = callError( data->error_signal, ee->what() );
}
else {
throw;
}
}
}
}
// Note: the signal is removed from the SignalHolder by
// freeSignal when the result is freed.
return ret;
}
typedef std::deque< boost::function< void() > > DisconnectCallback;
void disconnect_callback( void* userdata );
/** @endcond INTERNAL */
}
#endif // XMMSCLIENTPP_SIGNAL_H
|