Commit 035a6b32 authored by Emmanuel Milou's avatar Emmanuel Milou

[#1777] Code indentation/formatting

parent 4082f2e6
......@@ -31,23 +31,22 @@
#include <cstdio>
#include <stdlib.h>
static void _debug_log_default(const char *format, ...)
static void _debug_log_default (const char *format, ...)
{
#ifdef DEBUG
static int debug_env = getenv("DBUSXX_VERBOSE") ? 1 : 0;
static int debug_env = getenv ("DBUSXX_VERBOSE") ? 1 : 0;
if (debug_env)
{
va_list args;
va_start(args, format);
if (debug_env) {
va_list args;
va_start (args, format);
fprintf(stderr, "dbus-c++: ");
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
fprintf (stderr, "dbus-c++: ");
vfprintf (stderr, format, args);
fprintf (stderr, "\n");
va_end(args);
}
va_end (args);
}
#endif//DEBUG
}
......
......@@ -31,183 +31,183 @@
using namespace DBus;
Ecore::BusTimeout::BusTimeout( Timeout::Internal* ti)
: Timeout(ti)
Ecore::BusTimeout::BusTimeout (Timeout::Internal* ti)
: Timeout (ti)
{
_enable();
_enable();
}
Ecore::BusTimeout::~BusTimeout()
{
_disable();
_disable();
}
void Ecore::BusTimeout::toggle()
{
debug_log("ecore: timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off");
debug_log ("ecore: timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off");
if(Timeout::enabled()) _enable();
else _disable();
if (Timeout::enabled()) _enable();
else _disable();
}
int Ecore::BusTimeout::timeout_handler( void *data )
int Ecore::BusTimeout::timeout_handler (void *data)
{
Ecore::BusTimeout* t = reinterpret_cast<Ecore::BusTimeout*>(data);
Ecore::BusTimeout* t = reinterpret_cast<Ecore::BusTimeout*> (data);
debug_log("Ecore::BusTimeout::timeout_handler( void *data )");
debug_log ("Ecore::BusTimeout::timeout_handler( void *data )");
t->handle();
t->handle();
return 1; // 1 -> reshedule in ecore for next timer interval
return 1; // 1 -> reshedule in ecore for next timer interval
}
void Ecore::BusTimeout::_enable()
{
debug_log("Ecore::BusTimeout::_enable()");
_etimer = ecore_timer_add (((double)Timeout::interval())/1000, timeout_handler, this);
debug_log ("Ecore::BusTimeout::_enable()");
_etimer = ecore_timer_add ( ( (double) Timeout::interval()) /1000, timeout_handler, this);
}
void Ecore::BusTimeout::_disable()
{
debug_log("Ecore::BusTimeout::_disable()");
debug_log ("Ecore::BusTimeout::_disable()");
ecore_timer_del (_etimer);
ecore_timer_del (_etimer);
}
static bool watch_prepare( int *timeout )
static bool watch_prepare (int *timeout)
{
debug_log("ecore: watch_prepare");
debug_log ("ecore: watch_prepare");
*timeout = -1;
return false;
*timeout = -1;
return false;
}
static bool watch_check( )
static bool watch_check()
{
debug_log("ecore: watch_check");
debug_log ("ecore: watch_check");
return true;
return true;
}
static bool watch_dispatch( void *data )
static bool watch_dispatch (void *data)
{
debug_log("ecore: watch_dispatch");
debug_log ("ecore: watch_dispatch");
bool cb = true;
DBus::default_dispatcher->dispatch_pending(); //TODO: won't work in case of multiple dispatchers
return cb;
bool cb = true;
DBus::default_dispatcher->dispatch_pending(); //TODO: won't work in case of multiple dispatchers
return cb;
}
Ecore::BusWatch::BusWatch( Watch::Internal* wi)
: Watch(wi)
Ecore::BusWatch::BusWatch (Watch::Internal* wi)
: Watch (wi)
{
_enable();
_enable();
}
Ecore::BusWatch::~BusWatch()
{
_disable();
_disable();
}
void Ecore::BusWatch::toggle()
{
debug_log("ecore: watch %p toggled (%s)", this, Watch::enabled() ? "on":"off");
debug_log ("ecore: watch %p toggled (%s)", this, Watch::enabled() ? "on":"off");
if(Watch::enabled()) _enable();
else _disable();
if (Watch::enabled()) _enable();
else _disable();
}
int Ecore::BusWatch::watch_handler_read( void *data, Ecore_Fd_Handler *fdh )
int Ecore::BusWatch::watch_handler_read (void *data, Ecore_Fd_Handler *fdh)
{
Ecore::BusWatch* w = reinterpret_cast<Ecore::BusWatch*>(data);
Ecore::BusWatch* w = reinterpret_cast<Ecore::BusWatch*> (data);
debug_log ("ecore: watch_handler_read");
int flags = DBUS_WATCH_READABLE;
debug_log("ecore: watch_handler_read");
int flags = DBUS_WATCH_READABLE;
watch_dispatch(NULL);
watch_dispatch (NULL);
w->handle(flags);
w->handle (flags);
return 1;
return 1;
}
int Ecore::BusWatch::watch_handler_error( void *data, Ecore_Fd_Handler *fdh )
int Ecore::BusWatch::watch_handler_error (void *data, Ecore_Fd_Handler *fdh)
{
Ecore::BusWatch* w = reinterpret_cast<Ecore::BusWatch*>(data);
Ecore::BusWatch* w = reinterpret_cast<Ecore::BusWatch*> (data);
debug_log("ecore: watch_handler_error");
debug_log ("ecore: watch_handler_error");
int flags = DBUS_WATCH_ERROR;
watch_dispatch(NULL);
int flags = DBUS_WATCH_ERROR;
return 1;
watch_dispatch (NULL);
return 1;
}
void Ecore::BusWatch::_enable()
{
debug_log("Ecore::BusWatch::_enable()");
int flags = Watch::flags();
fd_handler_read = ecore_main_fd_handler_add (Watch::descriptor(),
ECORE_FD_READ,
watch_handler_read,
this,
NULL, NULL);
ecore_main_fd_handler_active_set(fd_handler_read, ECORE_FD_READ);
fd_handler_error = ecore_main_fd_handler_add (Watch::descriptor(),
ECORE_FD_ERROR,
watch_handler_error,
this,
NULL, NULL);
ecore_main_fd_handler_active_set(fd_handler_error, ECORE_FD_ERROR);
debug_log ("Ecore::BusWatch::_enable()");
int flags = Watch::flags();
fd_handler_read = ecore_main_fd_handler_add (Watch::descriptor(),
ECORE_FD_READ,
watch_handler_read,
this,
NULL, NULL);
ecore_main_fd_handler_active_set (fd_handler_read, ECORE_FD_READ);
fd_handler_error = ecore_main_fd_handler_add (Watch::descriptor(),
ECORE_FD_ERROR,
watch_handler_error,
this,
NULL, NULL);
ecore_main_fd_handler_active_set (fd_handler_error, ECORE_FD_ERROR);
}
void Ecore::BusWatch::_disable()
{
ecore_main_fd_handler_del (fd_handler_read);
ecore_main_fd_handler_del (fd_handler_error);
ecore_main_fd_handler_del (fd_handler_read);
ecore_main_fd_handler_del (fd_handler_error);
}
void Ecore::BusDispatcher::attach( )
void Ecore::BusDispatcher::attach()
{
}
Timeout* Ecore::BusDispatcher::add_timeout( Timeout::Internal* wi )
Timeout* Ecore::BusDispatcher::add_timeout (Timeout::Internal* wi)
{
Timeout* t = new Ecore::BusTimeout( wi );
Timeout* t = new Ecore::BusTimeout (wi);
debug_log("ecore: added timeout %p (%s)", t, t->enabled() ? "on":"off");
debug_log ("ecore: added timeout %p (%s)", t, t->enabled() ? "on":"off");
return t;
return t;
}
void Ecore::BusDispatcher::rem_timeout( Timeout* t )
void Ecore::BusDispatcher::rem_timeout (Timeout* t)
{
debug_log("ecore: removed timeout %p", t);
debug_log ("ecore: removed timeout %p", t);
delete t;
delete t;
}
Watch* Ecore::BusDispatcher::add_watch( Watch::Internal* wi )
Watch* Ecore::BusDispatcher::add_watch (Watch::Internal* wi)
{
Watch* w = new Ecore::BusWatch(wi);
Watch* w = new Ecore::BusWatch (wi);
debug_log("ecore: added watch %p (%s) fd=%d flags=%d",
w, w->enabled() ? "on":"off", w->descriptor(), w->flags()
);
return w;
debug_log ("ecore: added watch %p (%s) fd=%d flags=%d",
w, w->enabled() ? "on":"off", w->descriptor(), w->flags()
);
return w;
}
void Ecore::BusDispatcher::rem_watch( Watch* w )
void Ecore::BusDispatcher::rem_watch (Watch* w)
{
debug_log("ecore: removed watch %p", w);
debug_log ("ecore: removed watch %p", w);
delete w;
delete w;
}
......@@ -39,23 +39,23 @@ using namespace DBus;
*/
Error::Error()
: _int(new InternalError)
: _int (new InternalError)
{}
Error::Error(InternalError &i)
: _int(new InternalError(i))
Error::Error (InternalError &i)
: _int (new InternalError (i))
{}
Error::Error(const char *name, const char *message)
: _int(new InternalError)
Error::Error (const char *name, const char *message)
: _int (new InternalError)
{
set(name, message);
set (name, message);
}
Error::Error(Message &m)
: _int(new InternalError)
Error::Error (Message &m)
: _int (new InternalError)
{
dbus_set_error_from_message(&(_int->error), m._pvt->msg);
dbus_set_error_from_message (& (_int->error), m._pvt->msg);
}
Error::~Error() throw()
......@@ -64,26 +64,26 @@ Error::~Error() throw()
const char *Error::name() const
{
return _int->error.name;
return _int->error.name;
}
const char *Error::message() const
{
return _int->error.message;
return _int->error.message;
}
bool Error::is_set() const
{
return *(_int);
return * (_int);
}
void Error::set(const char *name, const char *message)
void Error::set (const char *name, const char *message)
{
dbus_set_error_const(&(_int->error), name, message);
dbus_set_error_const (& (_int->error), name, message);
}
const char *Error::what() const throw()
{
return _int->error.message;
return _int->error.message;
}
......@@ -34,133 +34,137 @@
using namespace DBus;
BusTimeout::BusTimeout(Timeout::Internal *ti, BusDispatcher *bd)
: Timeout(ti), DefaultTimeout(Timeout::interval(), true, bd)
BusTimeout::BusTimeout (Timeout::Internal *ti, BusDispatcher *bd)
: Timeout (ti), DefaultTimeout (Timeout::interval(), true, bd)
{
DefaultTimeout::enabled(Timeout::enabled());
DefaultTimeout::enabled (Timeout::enabled());
}
void BusTimeout::toggle()
{
debug_log("timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off");
debug_log ("timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off");
DefaultTimeout::enabled(Timeout::enabled());
DefaultTimeout::enabled (Timeout::enabled());
}
BusWatch::BusWatch(Watch::Internal *wi, BusDispatcher *bd)
: Watch(wi), DefaultWatch(Watch::descriptor(), 0, bd)
BusWatch::BusWatch (Watch::Internal *wi, BusDispatcher *bd)
: Watch (wi), DefaultWatch (Watch::descriptor(), 0, bd)
{
int flags = POLLHUP | POLLERR;
int flags = POLLHUP | POLLERR;
if (Watch::flags() & DBUS_WATCH_READABLE)
flags |= POLLIN;
if (Watch::flags() & DBUS_WATCH_WRITABLE)
flags |= POLLOUT;
if (Watch::flags() & DBUS_WATCH_READABLE)
flags |= POLLIN;
DefaultWatch::flags(flags);
DefaultWatch::enabled(Watch::enabled());
if (Watch::flags() & DBUS_WATCH_WRITABLE)
flags |= POLLOUT;
DefaultWatch::flags (flags);
DefaultWatch::enabled (Watch::enabled());
}
void BusWatch::toggle()
{
debug_log("watch %p toggled (%s)", this, Watch::enabled() ? "on":"off");
debug_log ("watch %p toggled (%s)", this, Watch::enabled() ? "on":"off");
DefaultWatch::enabled(Watch::enabled());
DefaultWatch::enabled (Watch::enabled());
}
void BusDispatcher::enter()
{
debug_log("entering dispatcher %p", this);
debug_log ("entering dispatcher %p", this);
_running = true;
_running = true;
while (_running)
{
do_iteration();
}
while (_running) {
do_iteration();
}
debug_log("leaving dispatcher %p", this);
debug_log ("leaving dispatcher %p", this);
}
void BusDispatcher::leave()
{
_running = false;
_running = false;
}
void BusDispatcher::do_iteration()
{
dispatch_pending();
dispatch();
dispatch_pending();
dispatch();
}
Timeout *BusDispatcher::add_timeout(Timeout::Internal *ti)
Timeout *BusDispatcher::add_timeout (Timeout::Internal *ti)
{
BusTimeout *bt = new BusTimeout(ti, this);
BusTimeout *bt = new BusTimeout (ti, this);
bt->expired = new Callback<BusDispatcher, void, DefaultTimeout &>(this, &BusDispatcher::timeout_expired);
bt->data(bt);
bt->expired = new Callback<BusDispatcher, void, DefaultTimeout &> (this, &BusDispatcher::timeout_expired);
bt->data (bt);
debug_log("added timeout %p (%s) interval=%d",
bt, ((Timeout *)bt)->enabled() ? "on":"off", ((Timeout *)bt)->interval());
debug_log ("added timeout %p (%s) interval=%d",
bt, ( (Timeout *) bt)->enabled() ? "on":"off", ( (Timeout *) bt)->interval());
return bt;
return bt;
}
void BusDispatcher::rem_timeout(Timeout *t)
void BusDispatcher::rem_timeout (Timeout *t)
{
debug_log("removed timeout %p", t);
debug_log ("removed timeout %p", t);
delete t;
delete t;
}
Watch *BusDispatcher::add_watch(Watch::Internal *wi)
Watch *BusDispatcher::add_watch (Watch::Internal *wi)
{
BusWatch *bw = new BusWatch(wi, this);
BusWatch *bw = new BusWatch (wi, this);
bw->ready = new Callback<BusDispatcher, void, DefaultWatch &>(this, &BusDispatcher::watch_ready);
bw->data(bw);
bw->ready = new Callback<BusDispatcher, void, DefaultWatch &> (this, &BusDispatcher::watch_ready);
bw->data (bw);
debug_log("added watch %p (%s) fd=%d flags=%d",
bw, ((Watch *)bw)->enabled() ? "on":"off", ((Watch *)bw)->descriptor(), ((Watch *)bw)->flags());
debug_log ("added watch %p (%s) fd=%d flags=%d",
bw, ( (Watch *) bw)->enabled() ? "on":"off", ( (Watch *) bw)->descriptor(), ( (Watch *) bw)->flags());
return bw;
return bw;
}
void BusDispatcher::rem_watch(Watch *w)
void BusDispatcher::rem_watch (Watch *w)
{
debug_log("removed watch %p", w);
debug_log ("removed watch %p", w);
delete w;
delete w;
}
void BusDispatcher::timeout_expired(DefaultTimeout &et)
void BusDispatcher::timeout_expired (DefaultTimeout &et)
{
debug_log("timeout %p expired", &et);
debug_log ("timeout %p expired", &et);
BusTimeout *timeout = reinterpret_cast<BusTimeout *>(et.data());
BusTimeout *timeout = reinterpret_cast<BusTimeout *> (et.data());
timeout->handle();
timeout->handle();
}
void BusDispatcher::watch_ready(DefaultWatch &ew)
void BusDispatcher::watch_ready (DefaultWatch &ew)
{
BusWatch *watch = reinterpret_cast<BusWatch *>(ew.data());
BusWatch *watch = reinterpret_cast<BusWatch *> (ew.data());
debug_log ("watch %p ready, flags=%d state=%d",
watch, ( (Watch *) watch)->flags(), watch->state()
);
int flags = 0;
if (watch->state() & POLLIN)
flags |= DBUS_WATCH_READABLE;
debug_log("watch %p ready, flags=%d state=%d",
watch, ((Watch *)watch)->flags(), watch->state()
);
if (watch->state() & POLLOUT)
flags |= DBUS_WATCH_WRITABLE;
int flags = 0;
if (watch->state() & POLLHUP)
flags |= DBUS_WATCH_HANGUP;
if (watch->state() & POLLIN)
flags |= DBUS_WATCH_READABLE;
if (watch->state() & POLLOUT)
flags |= DBUS_WATCH_WRITABLE;
if (watch->state() & POLLHUP)
flags |= DBUS_WATCH_HANGUP;
if (watch->state() & POLLERR)
flags |= DBUS_WATCH_ERROR;
if (watch->state() & POLLERR)
flags |= DBUS_WATCH_ERROR;
watch->handle(flags);
watch->handle (flags);
}
......@@ -35,64 +35,64 @@
using namespace DBus;
static double millis(timeval tv)
static double millis (timeval tv)
{
return (tv.tv_sec *1000.0 + tv.tv_usec/1000.0);
return (tv.tv_sec *1000.0 + tv.tv_usec/1000.0);
}
DefaultTimeout::DefaultTimeout(int interval, bool repeat, DefaultMainLoop *ed)
: _enabled(true), _interval(interval), _repeat(repeat), _expiration(0), _data(0), _disp(ed)
DefaultTimeout::DefaultTimeout (int interval, bool repeat, DefaultMainLoop *ed)
: _enabled (true), _interval (interval), _repeat (repeat), _expiration (0), _data (0), _disp (ed)
{
timeval now;
gettimeofday(&now, NULL);
timeval now;
gettimeofday (&now, NULL);
_expiration = millis(now) + interval;
_expiration = millis (now) + interval;
_disp->_mutex_t.lock();
_disp->_timeouts.push_back(this);
_disp->_mutex_t.unlock();
_disp->_mutex_t.lock();
_disp->_timeouts.push_back (this);
_disp->_mutex_t.unlock();
}