#include "TQObject.h"
#include "TQConnection.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TMethod.h"
#include "TBaseClass.h"
#include "TDataType.h"
#include "TInterpreter.h"
#include "TQClass.h"
#include "TError.h"
#include "G__ci.h"
#include "Api.h"
#include "Riostream.h"
#include "RQ_OBJECT.h"
#include "TVirtualMutex.h"
#include "Varargs.h"
#include "TCint.h"
#ifdef R__HAVE_CONFIG
#include "RConfigure.h"
#endif
void *gTQSender;
ClassImpQ(TQObject)
ClassImpQ(TQObjSender)
ClassImpQ(TQClass)
static char *ResolveTypes(const char *method)
{
if (!method || !*method) return 0;
char *str = new char[strlen(method)+1];
if (str) strcpy(str, method);
TString res;
char *s = strtok(str, "(");
res = s;
res += "(";
Bool_t first = kTRUE;
while ((s = strtok(0, ",)"))) {
char *s1, s2 = 0;
if ((s1 = strchr(s, '*'))) {
*s1 = 0;
s2 = '*';
}
if (!s1 && (s1 = strchr(s, '&'))) {
*s1 = 0;
s2 = '&';
}
TDataType *dt = gROOT->GetType(s);
if (s1) *s1 = s2;
if (!first) res += ",";
if (dt) {
res += dt->GetFullTypeName();
if (s1) res += s1;
} else
res += s;
first = kFALSE;
}
res += ")";
delete [] str;
str = new char[res.Length()+1];
strcpy(str, res.Data());
return str;
}
static char *CompressName(const char *method_name)
{
if (!method_name || !*method_name) return 0;
char *str = new char[strlen(method_name)+1];
if (str) strcpy(str, method_name);
char *tmp = str;
while ((tmp = strstr(tmp,"const"))) {
for (int i = 0; i < 5; i++) *(tmp+i) = ' ';
}
tmp = str;
char *s;
s = str;
Bool_t quote = kFALSE;
while (*tmp) {
if (*tmp == '\"')
quote = quote ? kFALSE : kTRUE;
if (*tmp != ' ' || quote)
*s++ = *tmp;
tmp++;
}
*s = '\0';
s = ResolveTypes(str);
delete [] str;
return s;
}
static TMethod *GetMethodWithPrototype(TClass *cl, const char *method,
const char *proto, Int_t &nargs)
{
nargs = 0;
if (!gInterpreter) return 0;
R__LOCKGUARD2(gCINTMutex);
Long_t faddr = 0;
if (!cl->IsLoaded()) {
G__MethodInfo meth;
long offset;
if (cl->GetClassInfo())
meth = cl->GetClassInfo()->GetMethod(method, proto, &offset);
if (meth.IsValid()) {
nargs = meth.NArg();
return (TMethod *) -1;
}
return 0;
} else {
faddr = (Long_t)gInterpreter->GetInterfaceMethodWithPrototype(cl, method,
proto);
if (!faddr) return 0;
}
TMethod *m;
TIter next_method(cl->GetListOfMethods());
while ((m = (TMethod *) next_method())) {
if (faddr == (Long_t)m->InterfaceMethod()) {
nargs = m->GetNargs();
return m;
}
}
TIter next_base(cl->GetListOfBases());
TBaseClass *base;
while ((base = (TBaseClass *)next_base())) {
TClass *c;
if ((c = base->GetClassPointer())) {
if ((m = GetMethodWithPrototype(c, method, proto, nargs))) return m;
}
}
return 0;
}
static TMethod *GetMethod(TClass *cl, const char *method, const char *params)
{
if (!gInterpreter) return 0;
R__LOCKGUARD2(gCINTMutex);
Long_t faddr = 0;
if (!cl->IsLoaded()) {
G__CallFunc func;
long offset;
func.SetFunc(cl->GetClassInfo(), method, params, &offset);
if (func.IsValid())
return (TMethod *) -1;
return 0;
} else {
faddr = (Long_t)gInterpreter->GetInterfaceMethod(cl, method, params);
if (!faddr) return 0;
}
TMethod *m;
TIter next_method(cl->GetListOfMethods());
while ((m = (TMethod *) next_method())) {
if (faddr == (Long_t)m->InterfaceMethod()) return m;
}
TIter next_base(cl->GetListOfBases());
TBaseClass *base;
while ((base = (TBaseClass *)next_base())) {
TClass *c;
if ((c = base->GetClassPointer())) {
if ((m = GetMethod(c,method,params))) return m;
}
}
return 0;
}
Int_t TQObject::CheckConnectArgs(TQObject *sender,
TClass *sender_class, const char *signal,
TClass *receiver_class, const char *slot)
{
char *signal_method = new char[strlen(signal)+1];
if (signal_method) strcpy(signal_method, signal);
char *signal_proto;
char *tmp;
if ((signal_proto = strchr(signal_method,'('))) {
*signal_proto++ = '\0';
if ((tmp = strrchr(signal_proto,')'))) *tmp = '\0';
}
if (!signal_proto) signal_proto = (char*)"";
if (sender && sender_class == TQObjSender::Class()) {
sender_class = gROOT->GetClass(sender->GetSenderClassName());
if (!sender_class) {
::Error("TQObject::CheckConnectArgs", "for signal/slot consistency\n"
"checking need to specify class name as argument to "
"RQ_OBJECT macro");
delete [] signal_method;
return -1;
}
}
Int_t nargs;
TMethod *signalMethod = GetMethodWithPrototype(sender_class,
signal_method,
signal_proto,
nargs);
if (!signalMethod) {
::Error("TQObject::CheckConnectArgs", "signal %s::%s(%s) does not exist",
sender_class->GetName(), signal_method, signal_proto);
delete [] signal_method;
return -1;
}
Int_t nsigargs = nargs;
#if defined(CHECK_COMMENT_STRING)
const char *comment = 0;
if (signalMethod != (TMethod *) -1)
comment = signalMethod->GetCommentString();
if (!comment || !strlen(comment) || strstr(comment,"*SIGNAL")){
::Error("TQObject::CheckConnectArgs",
"signal %s::%s(%s), to declare signal use comment //*SIGNAL*",
sender_class->GetName(), signal_method, signal_proto);
delete [] signal_method;
return -1;
}
#endif
delete [] signal_method;
char *slot_method = new char[strlen(slot)+1];
if (slot_method) strcpy(slot_method, slot);
char *slot_proto;
char *slot_params = 0;
if ((slot_proto = strchr(slot_method,'('))) {
*slot_proto++ = '\0';
if ((tmp = strrchr(slot_proto,')'))) *tmp = '\0';
}
if (!slot_proto) slot_proto = (char*)"";
if ((slot_params = strchr(slot_proto,'='))) *slot_params = ' ';
TFunction *slotMethod = 0;
if (!receiver_class) {
slotMethod = (TFunction*)gROOT->GetListOfGlobalFunctions(kTRUE)->
FindObject(slot_method);
} else {
slotMethod = !slot_params ?
GetMethodWithPrototype(receiver_class,
slot_method,
slot_proto,
nargs) :
GetMethod(receiver_class,
slot_method, slot_params);
}
if (!slotMethod) {
if (!slot_params) {
::Error("TQObject::CheckConnectArgs", "slot %s(%s) does not exist",
receiver_class ? Form("%s::%s", receiver_class->GetName(),
slot_method) : slot_method, slot_proto);
} else {
::Error("TQObject::CheckConnectArgs", "slot %s(%s) does not exist",
receiver_class ? Form("%s::%s", receiver_class->GetName(),
slot_method) : slot_method, slot_params);
}
delete [] slot_method;
return -1;
}
#if defined(CHECK_ARGS_NUMBER)
if (slotMethod != (TMethod *) -1 && slotMethod->GetNargsOpt() >= 0 &&
nsigargs < (slotMethod->GetNargs() - slotMethod->GetNargsOpt())) {
::Error("TQObject::CheckConnectArgs",
"inconsistency in numbers of arguments");
delete [] slot_method;
return -1;
}
#endif
delete [] slot_method;
return nsigargs;
}
class TQConnectionList : public TList {
private:
Int_t fSignalArgs;
public:
TQConnectionList(const char *name, Int_t nsigargs) : TList()
{ fName = name; fSignalArgs = nsigargs; }
virtual ~TQConnectionList();
Bool_t Disconnect(void *receiver=0, const char *slot_name=0);
Int_t GetNargs() const { return fSignalArgs; }
void ls(Option_t *option = "") const;
void Print(Option_t *option = "") const;
void Print(Option_t *, Option_t *option) const { Print(option); }
};
TQConnectionList::~TQConnectionList()
{
TIter next(this);
TQConnection *connection;
while ((connection = (TQConnection*)next())) {
connection->Remove(this);
if (connection->IsEmpty()) delete connection;
}
Clear("nodelete");
}
Bool_t TQConnectionList::Disconnect(void *receiver, const char *slot_name)
{
TQConnection *connection = 0;
Bool_t return_value = kFALSE;
TObjLink *lnk = FirstLink();
TObjLink *savlnk;
while (lnk) {
connection = (TQConnection*)lnk->GetObject();
const char *name = connection->GetName();
void *obj = connection->GetReceiver();
if (!slot_name || !strlen(slot_name)
|| !strcmp(name,slot_name)) {
if (!receiver || (receiver == obj)) {
return_value = kTRUE;
savlnk = lnk->Next();
Remove(lnk);
lnk = savlnk;
connection->Remove(this);
if (connection->IsEmpty()) SafeDelete(connection);
continue;
}
}
lnk = lnk->Next();
}
return return_value;
}
void TQConnectionList::ls(Option_t *option) const
{
cout << "TQConnectionList:" << "\t" << GetName() << endl;
((TQConnectionList*)this)->R__FOR_EACH(TQConnection,Print)(option);
}
void TQConnectionList::Print(Option_t *) const
{
cout << "TQConnectionList:" << "\t" << GetName() << endl;
}
TQObject::TQObject()
{
fListOfSignals = 0;
fListOfConnections = 0;
}
TQObject::~TQObject()
{
if (!gROOT) return;
Destroyed();
if (fListOfSignals) {
fListOfSignals->Delete();
SafeDelete(fListOfSignals);
}
if (fListOfConnections) {
TIter next_connection(fListOfConnections);
TQConnection *connection;
while ((connection = (TQConnection*)next_connection())) {
TIter next_list(connection);
TQConnectionList *list;
while ((list = (TQConnectionList*)next_list())) {
list->Remove(connection);
if (list->IsEmpty()) SafeDelete(list);
}
}
SafeDelete(fListOfConnections);
}
}
TList *TQObject::GetListOfClassSignals() const
{
TQClass *qcl = 0;
qcl = dynamic_cast<TQClass*>(IsA());
return qcl ? qcl->fListOfSignals : 0;
}
void TQObject::HighPriority(const char *signal_name, const char *slot_name)
{
TQConnectionList *clist = 0;
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal_name,clist->GetName()))
break;
}
if (!clist) return;
if (!slot_name) {
fListOfSignals->Remove(clist);
fListOfSignals->AddFirst(clist);
return;
} else {
TQConnection *con = 0;
TIter next_con(clist);
while ((con = (TQConnection*)next_con())) {
if (!strcmp(slot_name,con->GetName()))
break;
}
if (!con) return;
clist->Remove(con);
clist->AddFirst(con);
}
}
void TQObject::LowPriority(const char *signal_name, const char *slot_name)
{
TQConnectionList *clist = 0;
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal_name,clist->GetName()))
break;
}
if (!clist) return;
if (!slot_name) {
fListOfSignals->Remove(clist);
fListOfSignals->AddLast(clist);
return;
} else {
TQConnection *con = 0;
TIter next_con(clist);
while ((con = (TQConnection*)next_con())) {
if (!strcmp(slot_name,con->GetName())) break;
}
if (!con) return;
clist->Remove(con);
clist->AddLast(con);
}
}
Bool_t TQObject::HasConnection(const char *signal_name) const
{
if (!fListOfSignals)
return kFALSE;
register TQConnectionList *clist = 0;
char *signal = CompressName(signal_name);
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal, clist->GetName())) {
delete [] signal;
return kTRUE;
}
}
delete [] signal;
return kFALSE;
}
Int_t TQObject::NumberOfSignals() const
{
if (fListOfSignals)
return fListOfSignals->GetSize();
return 0;
}
Int_t TQObject::NumberOfConnections() const
{
if (fListOfConnections)
return fListOfConnections->GetSize();
return 0;
}
void TQObject::Emit(const char *signal_name)
{
TList *slist = GetListOfClassSignals();
if ((!slist && !fListOfSignals) || !signal_name)
return;
register TQConnectionList *clist = 0;
register TQConnection *connection = 0;
char *signal = CompressName(signal_name);
if (slist) {
TIter nextcl_list(slist);
while ((clist = (TQConnectionList*)nextcl_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (clist) {
TIter nextcl(clist);
while ((connection = (TQConnection*)nextcl())) {
gTQSender = GetSender();
connection->ExecuteMethod();
}
}
}
if (!fListOfSignals) {
delete [] signal;
return;
}
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (!clist) {
delete [] signal;
return;
}
TIter next(clist);
while (fListOfSignals && (connection = (TQConnection*)next())) {
gTQSender = GetSender();
connection->ExecuteMethod();
}
delete [] signal;
}
void TQObject::EmitVA(const char *signal_name, Int_t va_(nargs), ...)
{
va_list ap;
va_start(ap, va_(nargs));
EmitVA(signal_name, va_(nargs), ap);
va_end(ap);
}
void TQObject::EmitVA(const char *signal_name, Int_t nargs, va_list ap)
{
TList *slist = GetListOfClassSignals();
if ((!slist && !fListOfSignals) || !signal_name)
return;
register TQConnectionList *clist = 0;
register TQConnection *connection = 0;
char *signal = CompressName(signal_name);
if (slist) {
TIter nextcl_list(slist);
while ((clist = (TQConnectionList*)nextcl_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (clist) {
TIter nextcl(clist);
while ((connection = (TQConnection*)nextcl())) {
gTQSender = GetSender();
connection->ExecuteMethod(nargs, ap);
}
}
}
if (!fListOfSignals) {
delete [] signal;
return;
}
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (!clist) {
delete [] signal;
return;
}
TIter next(clist);
while (fListOfSignals && (connection = (TQConnection*)next())) {
gTQSender = GetSender();
connection->ExecuteMethod(nargs, ap);
}
delete [] signal;
}
void TQObject::Emit(const char *signal_name, Long_t param)
{
TList *slist = GetListOfClassSignals();
if ((!slist && !fListOfSignals) || !signal_name)
return;
register TQConnectionList *clist = 0;
register TQConnection *connection = 0;
char *signal = CompressName(signal_name);
if (slist) {
TIter nextcl_list(slist);
while ((clist = (TQConnectionList*)nextcl_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (clist) {
TIter nextcl(clist);
while ((connection = (TQConnection*)nextcl())) {
gTQSender = GetSender();
connection->ExecuteMethod(param);
}
}
}
if (!fListOfSignals) {
delete [] signal;
return;
}
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (!clist) {
delete [] signal;
return;
}
TIter next(clist);
while (fListOfSignals && (connection = (TQConnection*)next())) {
gTQSender = GetSender();
connection->ExecuteMethod(param);
}
delete [] signal;
}
void TQObject::Emit(const char *signal_name, Long64_t param)
{
TList *slist = GetListOfClassSignals();
if ((!slist && !fListOfSignals) || !signal_name)
return;
register TQConnectionList *clist = 0;
register TQConnection *connection = 0;
char *signal = CompressName(signal_name);
if (slist) {
TIter nextcl_list(slist);
while ((clist = (TQConnectionList*)nextcl_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (clist) {
TIter nextcl(clist);
while ((connection = (TQConnection*)nextcl())) {
gTQSender = GetSender();
connection->ExecuteMethod(param);
}
}
}
if (!fListOfSignals) {
delete [] signal;
return;
}
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (!clist) {
delete [] signal;
return;
}
TIter next(clist);
while (fListOfSignals && (connection = (TQConnection*)next())) {
gTQSender = GetSender();
connection->ExecuteMethod(param);
}
delete [] signal;
}
void TQObject::Emit(const char *signal_name, Double_t param)
{
TList *slist = GetListOfClassSignals();
if ((!slist && !fListOfSignals) || !signal_name)
return;
register TQConnectionList *clist = 0;
register TQConnection *connection = 0;
char *signal = CompressName(signal_name);
if (slist) {
TIter nextcl_list(slist);
while ((clist = (TQConnectionList*)nextcl_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (clist) {
TIter nextcl(clist);
while ((connection = (TQConnection*)nextcl())) {
gTQSender = GetSender();
connection->ExecuteMethod(param);
}
}
}
if (!fListOfSignals) {
delete [] signal;
return;
}
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (!clist) {
delete [] signal;
return;
}
TIter next(clist);
while (fListOfSignals && (connection = (TQConnection*)next())) {
gTQSender = GetSender();
connection->ExecuteMethod(param);
}
delete [] signal;
}
void TQObject::Emit(const char *signal_name, const char *params)
{
TList *slist = GetListOfClassSignals();
if ((!slist && !fListOfSignals) || !signal_name)
return;
register TQConnectionList *clist = 0;
register TQConnection *connection = 0;
char *signal = CompressName(signal_name);
if (slist) {
TIter nextcl_list(slist);
while ((clist = (TQConnectionList*)nextcl_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (clist) {
TIter nextcl(clist);
while ((connection = (TQConnection*)nextcl())) {
gTQSender = GetSender();
connection->ExecuteMethod(params);
}
}
}
if (!fListOfSignals) {
delete [] signal;
return;
}
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (!clist) {
delete [] signal;
return;
}
TIter next(clist);
while (fListOfSignals && (connection = (TQConnection*)next())) {
gTQSender = GetSender();
connection->ExecuteMethod(params);
}
delete [] signal;
}
void TQObject::Emit(const char *signal_name, Long_t *paramArr)
{
TList *slist = GetListOfClassSignals();
if ((!slist && !fListOfSignals) || !signal_name)
return;
register TQConnectionList *clist = 0;
register TQConnection *connection = 0;
char *signal = CompressName(signal_name);
if (slist) {
TIter nextcl_list(slist);
while ((clist = (TQConnectionList*)nextcl_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (clist) {
TIter nextcl(clist);
while ((connection = (TQConnection*)nextcl())) {
gTQSender = GetSender();
connection->ExecuteMethod(paramArr, clist->GetNargs());
}
}
}
if (!fListOfSignals) {
delete [] signal;
return;
}
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal,clist->GetName())) break;
}
if (!clist) {
delete [] signal;
return;
}
TIter next(clist);
while (fListOfSignals && (connection = (TQConnection*)next())) {
gTQSender = GetSender();
connection->ExecuteMethod(paramArr, clist->GetNargs());
}
delete [] signal;
}
Bool_t TQObject::ConnectToClass(TQObject *sender,
const char *signal,
TClass *cl,
void *receiver,
const char *slot)
{
if (!sender->IsA()->InheritsFrom(TQObject::Class()))
return kFALSE;
char *signal_name = CompressName(signal);
char *slot_name = CompressName(slot);
Int_t nsigargs;
if ((nsigargs = CheckConnectArgs(sender, sender->IsA(), signal_name, cl, slot_name)) == -1)
return kFALSE;
if (!sender->fListOfSignals)
sender->fListOfSignals = new TList();
TQConnectionList *clist=0;
TIter next_list(sender->fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal_name,clist->GetName())) break;
}
if (!clist) {
clist = new TQConnectionList(signal_name, nsigargs);
sender->fListOfSignals->Add(clist);
}
TIter next(clist);
TQConnection *connection = 0;
while ((connection = (TQConnection*)next())) {
if (!strcmp(slot_name,connection->GetName()) &&
(receiver == connection->GetReceiver())) break;
}
if (!connection)
connection = new TQConnection(cl, receiver, slot_name);
if (!clist->FindObject(connection)) {
clist->Add(connection);
if (!connection->FindObject(clist)) connection->Add(clist);
sender->Connected(signal_name);
}
if (signal_name) { delete [] signal_name; signal_name = 0; }
if (slot_name) { delete [] slot_name; slot_name = 0; }
return kTRUE;
}
Bool_t TQObject::ConnectToClass(const char *class_name,
const char *signal,
TClass *cl,
void *receiver,
const char *slot)
{
TClass *sender = gROOT->GetClass(class_name);
if (!sender || !sender->IsA()->InheritsFrom(TQObject::Class()))
return kFALSE;
TList *slist = ((TQClass*)sender)->fListOfSignals;
char *signal_name = CompressName(signal);
char *slot_name = CompressName(slot);
Int_t nsigargs;
if ((nsigargs = CheckConnectArgs(0, sender, signal_name, cl, slot_name)) == -1)
return kFALSE;
TQConnectionList *clist = 0;
if (!slist)
((TQClass*)sender)->fListOfSignals = slist = new TList();
TIter next_list(slist);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal_name,clist->GetName())) break;
}
if (!clist) {
clist = new TQConnectionList(signal_name, nsigargs);
slist->Add(clist);
}
TQConnection *connection = 0;
TIter next(clist);
while ((connection = (TQConnection*)next())) {
if (!strcmp(slot_name,connection->GetName()) &&
(receiver == connection->GetReceiver())) break;
}
if (!connection)
connection = new TQConnection(cl, receiver, slot_name);
if (!clist->FindObject(connection)) {
clist->Add(connection);
if (!connection->FindObject(clist)) connection->Add(clist);
((TQClass*)sender)->Connected(signal_name);
}
if (signal_name) { delete [] signal_name; signal_name = 0; }
if (slot_name) { delete [] slot_name; slot_name = 0; }
return kTRUE;
}
Bool_t TQObject::Connect(TQObject *sender,
const char *signal,
const char *cl,
void *receiver,
const char *slot)
{
if (cl) {
TClass *rcv_cl = gROOT->GetClass(cl);
if (rcv_cl) return ConnectToClass(sender, signal, rcv_cl, receiver, slot);
}
if (!sender->IsA()->InheritsFrom(TQObject::Class()))
return kFALSE;
char *signal_name = CompressName(signal);
char *slot_name = CompressName(slot);
Int_t nsigargs;
if ((nsigargs = CheckConnectArgs(sender, sender->IsA(), signal_name, 0, slot_name)) == -1)
return kFALSE;
if (!sender->fListOfSignals) sender->fListOfSignals = new TList();
TQConnectionList *clist = 0;
TIter next_list(sender->fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal_name,clist->GetName())) break;
}
if (!clist) {
clist = new TQConnectionList(signal_name, nsigargs);
sender->fListOfSignals->Add(clist);
}
TQConnection *connection = 0;
TIter next(clist);
while ((connection = (TQConnection*)next())) {
if (!strcmp(slot_name,connection->GetName()) &&
(receiver == connection->GetReceiver())) break;
}
if (!connection)
connection = new TQConnection(cl, receiver, slot_name);
if (!clist->FindObject(connection)) {
clist->Add(connection);
if (!connection->FindObject(clist)) connection->Add(clist);
sender->Connected(signal_name);
}
if (signal_name) { delete [] signal_name; signal_name = 0; }
if (slot_name) { delete [] slot_name; slot_name = 0; }
return kTRUE;
}
Bool_t TQObject::Connect(const char *class_name,
const char *signal,
const char *cl,
void *receiver,
const char *slot)
{
if (cl) {
TClass *rcv_cl = gROOT->GetClass(cl);
if (rcv_cl) return ConnectToClass(class_name, signal, rcv_cl, receiver,
slot);
}
TClass *sender = gROOT->GetClass(class_name);
if (!sender || !sender->IsA()->InheritsFrom(TQObject::Class()))
return kFALSE;
TList *slist = ((TQClass*)sender)->fListOfSignals;
char *signal_name = CompressName(signal);
char *slot_name = CompressName(slot);
Int_t nsigargs;
if ((nsigargs = CheckConnectArgs(0, sender, signal_name, 0, slot_name)) == -1)
return kFALSE;
TQConnectionList *clist = 0;
if (!slist) {
slist = ((TQClass*)sender)->fListOfSignals = new TList();
}
TIter next_list(slist);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal_name,clist->GetName())) break;
}
if (!clist) {
clist = new TQConnectionList(signal_name, nsigargs);
slist->Add(clist);
}
TQConnection *connection = 0;
TIter next(clist);
while ((connection = (TQConnection*)next())) {
if (!strcmp(slot_name,connection->GetName()) &&
(receiver == connection->GetReceiver())) break;
}
if (!connection)
connection = new TQConnection(cl, receiver, slot_name);
if (!clist->FindObject(connection)) {
clist->Add(connection);
if (!connection->FindObject(clist)) connection->Add(clist);
((TQClass*)sender)->Connected(signal_name);
}
if (signal_name) { delete [] signal_name; signal_name = 0; }
if (slot_name) { delete [] slot_name; slot_name = 0; }
return kTRUE;
}
Bool_t TQObject::Connect(const char *signal,
const char *receiver_class,
void *receiver,
const char *slot)
{
char *signal_name = CompressName(signal);
char *slot_name = CompressName(slot);
TClass *cl = 0;
if (receiver_class)
cl = gROOT->GetClass(receiver_class);
Int_t nsigargs;
if ((nsigargs = CheckConnectArgs(this, IsA(), signal_name, cl, slot_name)) == -1)
return kFALSE;
if (!fListOfSignals) fListOfSignals = new TList();
TQConnectionList *clist = 0;
TIter next_list(fListOfSignals);
while ((clist = (TQConnectionList*)next_list())) {
if (!strcmp(signal_name,clist->GetName())) break;
}
if (!clist) {
clist = new TQConnectionList(signal_name, nsigargs);
fListOfSignals->Add(clist);
}
TIter next(clist);
TQConnection *connection = 0;
while ((connection = (TQConnection*)next())) {
if (!strcmp(slot_name,connection->GetName()) &&
(receiver == connection->GetReceiver())) break;
}
if (!connection)
connection = new TQConnection(receiver_class, receiver, slot_name);
if (!clist->FindObject(connection)) {
clist->Add(connection);
if (!connection->FindObject(clist)) connection->Add(clist);
Connected(signal_name);
}
if (signal_name) { delete [] signal_name; signal_name = 0; }
if (slot_name) { delete [] slot_name; slot_name = 0; }
return kTRUE;
}
Bool_t TQObject::Disconnect(TQObject *sender,
const char *signal,
void *receiver,
const char *slot)
{
Bool_t return_value = kFALSE;
Bool_t next_return = kFALSE;
if (!sender->GetListOfSignals()) return kFALSE;
char *signal_name = CompressName(signal);
char *slot_name = CompressName(slot);
TQConnectionList *slist = 0;
TIter next_signal(sender->GetListOfSignals());
while ((slist = (TQConnectionList*)next_signal())) {
if (!signal_name) {
next_return = slist->Disconnect(receiver,slot_name);
return_value = return_value || next_return;
if (slist->IsEmpty()) {
sender->GetListOfSignals()->Remove(slist);
SafeDelete(slist);
}
} else if (signal && !strcmp(signal_name,slist->GetName())) {
next_return = slist->Disconnect(receiver,slot_name);
return_value = return_value || next_return;
if (slist->IsEmpty()) {
sender->GetListOfSignals()->Remove(slist);
SafeDelete(slist);
break;
}
}
}
if (sender->GetListOfSignals() && sender->GetListOfSignals()->IsEmpty()) {
SafeDelete(sender->fListOfSignals);
}
if (signal_name) { delete [] signal_name; signal_name = 0; }
if (slot_name) { delete [] slot_name; slot_name = 0; }
return return_value;
}
Bool_t TQObject::Disconnect(const char *class_name,
const char *signal,
void *receiver,
const char *slot)
{
TClass *sender = gROOT->GetClass(class_name);
if (!sender->IsA()->InheritsFrom(TQObject::Class()))
return kFALSE;
TQClass *qcl = (TQClass*)sender;
return Disconnect(qcl, signal, receiver, slot);
}
Bool_t TQObject::Disconnect(const char *signal,
void *receiver,
const char *slot)
{
return Disconnect(this, signal, receiver, slot);
}
void TQObject::Streamer(TBuffer &R__b)
{
if (R__b.IsReading()) {
} else {
}
}
void TQObject::LoadRQ_OBJECT()
{
G__load_text(RQ_OBJECT_STRING1);
G__load_text(RQ_OBJECT_STRING2);
G__load_text(RQ_OBJECT_STRING);
}
Bool_t ConnectCINT(TQObject *sender, const char *signal, const char *slot)
{
TString str = "ProcessLine(=";
str += '"';
str += slot;
str += '"';
str += ")";
return TQObject::Connect(sender, signal, "TInterpreter",
gInterpreter, str.Data());
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.