/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" /* * This class provides a signal framework to classes that inherit from it. * This should be a parent of all non-data structure classes. */ /* * Initializes the object and sets up n signals. */ kryObject::kryObject(int nSignals) { if(nSignals < 0) { g_warning("Attempting to create an object with a negative amount of signals."); nSignals = 0; } this->m_signals = new krySignal[nSignals]; this->m_n_signals = nSignals; } /* * Assigns one Object to another. * * Note that callbacks connected to the object being assigned are not copied to this object. */ void kryObject::operator =(kryObject & object) { this->m_signals = new krySignal[this->m_n_signals]; } /* * Destroys the kryObject. */ kryObject::~kryObject() { if(this->m_signals) delete[] this->m_signals; } /* * Checks if the given Signal ID falls within the allowed range. * * Returns FALSE if the id is not valid. */ gboolean kryObject::CheckId(int id) { if(id < 0 || id > this->m_n_signals) { g_warning("Signal ID is out of range. Less than 0 or greater than %d.", this->m_n_signals); return FALSE; } return TRUE; } /* * If the signal was previously disabled, resumes invokation of callbacks. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. */ void kryObject::EnableSignal(int id) { if(!this->CheckId(id)) return; this->m_signals[id].Enable(); } /* * Disables the signal, preventing any callbacks from being invokes. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. */ void kryObject::DisableSignal(int id) { if(!this->CheckId(id)) return; this->m_signals[id].Disable(); } /* * Connects the given function to the signal identified by the given id. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. * Returns the ID of the connected callback or 0 if the signal ID is not valid. */ long kryObject::ConnectSignal(int id, krySignalFunc0 func) { if(!this->CheckId(id)) { g_warning("connect check id failed"); return 0; } return this->m_signals[id].Connect(func); } /* * Connects the given function to the signal identified by the given id. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. * Returns the ID of the connected callback or 0 if the signal ID is not valid. */ long kryObject::ConnectSignal(int id, krySignalFunc1 func, void *connect_data1) { if(!this->CheckId(id)) { g_warning("connect check id failed"); return 0; } return this->m_signals[id].Connect(func, connect_data1); } /* * Connects the given function to the signal identified by the given id. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. * Returns the ID of the connected callback or 0 if the signal ID is not valid. */ long kryObject::ConnectSignal(int id, krySignalFunc2 func, void *connect_data1, void *connect_data2) { if(!this->CheckId(id)) { g_warning("connect check id failed"); return 0; } return this->m_signals[id].Connect(func, connect_data1, connect_data2); } /* * Disconnects the given function from the signal identified by the given id. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. */ void kryObject::DisconnectSignal(int id, void *func) { if(!this->CheckId(id)) return; this->m_signals[id].Disconnect(func); } /* * Disconnects the given callback id from the signal identified by the given id. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. */ void kryObject::DisconnectSignal(int id, int id_sig) { if(!this->CheckId(id)) return; this->m_signals[id].Disconnect(id_sig); } /* * Causes all the callbacks for the given signal to be invoked. * * This is just a wrapper function for the krySignal class. * See krySignal for parameter information. * * If the ID is not valid, nothing is affected. */ void kryObject::InvokeSignal(int id, void *param) { if(!this->CheckId(id)) return; this->m_signals[id].Invoke(this, param); }