author | wimpie <wimpie> | 2005-01-04 04:13:29 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-04 04:13:29 (UTC) |
commit | 12e7c838d741d37c7a526e21ac43562ec5b64c6e (patch) (side-by-side diff) | |
tree | 3fe816a5dd68bc11a73dbb4b4144a41323041f21 | |
parent | a268c0ab03aed309a1a8f65350ef894c81142785 (diff) | |
download | opie-12e7c838d741d37c7a526e21ac43562ec5b64c6e.zip opie-12e7c838d741d37c7a526e21ac43562ec5b64c6e.tar.gz opie-12e7c838d741d37c7a526e21ac43562ec5b64c6e.tar.bz2 |
Some more logging
3 files changed, 8 insertions, 3 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index 17653bd..f8f2d1e 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -1,511 +1,512 @@ #include <time.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpainter.h> #include <qbitmap.h> #include <qtextstream.h> #include <qpixmap.h> #include "resources.h" #include "netnode.h" static char * ActionName[] = { "Disable", "Enable", "Activate", "Deactivate", "Up", "Down" }; static char * StateName[] = { "Unchecked", "Unknown", "Unavailable", "Disabled", "Off", "Available", "IsUp" }; QString & deQuote( QString & X ) { if( X[0] == '"' ) { // remove end and trailing "" and \x -> x QChar R; long idx; idx = X.length()-1; X = X.mid( 1, idx ); idx = 0; while( ( idx = X.find( '\\', idx ) ) >= 0 ) { R = X.at( idx + 1 ); X.replace( idx, 2, &R, 1 ); } X = X.left( X.length()-1 ); } return X; } QString quote( QString X ) { if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { // need to quote this QString OutString = "\""; X.replace( QRegExp("\""), "\\\"" ); X.replace( QRegExp("\\"), "\\\\" ); X.replace( QRegExp(" "), "\\ " ); OutString += X; OutString += "\""; X = OutString; } return X; } // // // ANETNODE // // void ANetNode::saveAttributes( QTextStream & TS ) { saveSpecificAttribute( TS ); } void ANetNode::setAttribute( QString & Attr, QString & Value ){ setSpecificAttribute( Attr, Value ); } bool ANetNode::isToplevel( void ) { const char ** P = provides(); while( *P ) { if( strcmp( *P, "fullsetup") == 0 ) return 1; P ++; } return 0; } bool ANetNode::openFile( SystemFile & SF, ANetNodeInstance * NNI ) { return (NNI ) ? NNI->openFile( SF ) : 0 ; } // // // ANETNODEINSTANCE // // long ANetNodeInstance::InstanceCounter = -1; void ANetNodeInstance::initialize( void ) { if( InstanceCounter == -1 ) InstanceCounter = time(0); // set name QString N; N.sprintf( "-%ld", InstanceCounter++ ); N.prepend( NodeType->name() ); setName( N.latin1() ); } void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ if( Attr == "__name" ) { setName( Value.latin1() ); } else { setSpecificAttribute( Attr, Value ); } } void ANetNodeInstance::saveAttributes( QTextStream & TS ) { TS << "__name=" << name() << endl; saveSpecificAttribute( TS ); } ANetNodeInstance * ANetNodeInstance::nextNode( void ) { return connection()->findNext( this ); } // // // NODECOLLECTION // // NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { IsModified = 0; Index = -1; Name=""; IsNew = 1; CurrentState = Unchecked; AssignedInterface = 0; } NodeCollection::NodeCollection( QTextStream & TS ) : QList<ANetNodeInstance>() { long idx; bool InError = 0; QString S, A, N; IsModified = 0; Index = -1; Name=""; IsNew = 0; AssignedInterface = 0; CurrentState = Unchecked; do { S = TS.readLine(); if( S.isEmpty() ) { if( InError ) { // remove all nodes clear(); } // empty line break; } idx = S.find('='); S.stripWhiteSpace(); A = S.left( idx ); A.lower(); N = S.mid( idx+1, S.length() ); N.stripWhiteSpace(); N = deQuote( N ); if( A == "name" ) { Name = N; } else if( A == "number" ) { setNumber( N.toLong() ); } else if( A == "node" ) { ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); + Log(( "Find node %s : %p\n", N.latin1(), NNI )); if( NNI && ! InError ) { - append( NSResources->findNodeInstance( N ) ); + append( NNI ); } else { // could not find a node type -> collection invalid InError = 1; } } } while( 1 ); Log(( "Profile number %s : %d nodes\n", - N.latin1(), count() )); + Name.latin1(), count() )); } NodeCollection::~NodeCollection( void ) { } const QString & NodeCollection::description( void ) { ANetNodeInstance * NNI = getToplevel(); return (NNI) ? NNI->runtime()->description() : Name; } void NodeCollection::append( ANetNodeInstance * NNI ) { NNI->setConnection( this ); QList<ANetNodeInstance>::append( NNI ); } void NodeCollection::save( QTextStream & TS ) { TS << "name=" << quote( Name ) << endl; TS << "number=" << number() << endl; ANetNodeInstance * NNI; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); TS << "node=" << NNI->name() << endl; } TS << endl; IsNew = 0; } ANetNodeInstance * NodeCollection::getToplevel( void ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->nodeClass()->isToplevel() ) break; } return NNI; } ANetNodeInstance * NodeCollection::findByName( const QString & S ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->name() == S ) break; } return NNI; } ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { ANetNodeInstance * NNNI; if( ! NNI ) getToplevel(); for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNNI = it.current(); if( NNNI == NNI ) { ++it; return it.current(); } } return 0; // no more next } int NodeCollection::compareItems( QCollection::Item I1, QCollection::Item I2 ) { ANetNodeInstance * NNI1, * NNI2; NNI1 = (ANetNodeInstance *)I1; NNI2 = (ANetNodeInstance *)I2; return strcmp( NNI1->name(), NNI2->name() ); } static char * State2PixmapTbl[] = { "NULL", // Unchecked : no pixmap "check", // Unknown "delete", // unavailable "disabled", // disabled "off", // off "disconnected", // available "connected" // up }; QPixmap NodeCollection::devicePixmap( void ) { QPixmap pm = NSResources->getPixmap( getToplevel()->nextNode()->pixmapName()+"-large"); QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() ); if( pm.isNull() || Mini.isNull() ) return Resource::loadPixmap("Unknown"); QPainter painter( &pm ); painter.drawPixmap( pm.width()-Mini.width(), pm.height()-Mini.height(), Mini ); pm.setMask( pm.createHeuristicMask( TRUE ) ); return pm; } QPixmap NodeCollection::statePixmap( State_t S) { return NSResources->getPixmap( State2PixmapTbl[S] ); } QString NodeCollection::stateName( State_t S) { switch( S ) { case Unknown : return qApp->translate( "networksettings2", "Unknown"); case Unavailable : return qApp->translate( "networksettings2", "Unavailable"); case Disabled : return qApp->translate( "networksettings2", "Disabled"); case Off : return qApp->translate( "networksettings2", "Inactive"); case Available : return qApp->translate( "networksettings2", "Available"); case IsUp : return qApp->translate( "networksettings2", "Up"); case Unchecked : /* FT */ default : break; } return QString(""); } void NodeCollection::reassign( void ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { it.current()->setConnection( this ); } } const QStringList & NodeCollection::triggers() { return getToplevel()->runtime()->triggers(); } bool NodeCollection::hasDataForFile( SystemFile & S ) { return ( firstWithDataForFile( S ) != 0 ); } ANetNodeInstance * NodeCollection::firstWithDataForFile( SystemFile & S ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { if( it.current()->hasDataForFile( S ) ) { return it.current(); } } return 0; } State_t NodeCollection::state( bool Update ) { State_t NodeState; if( CurrentState == Unchecked || Update ) { // collect states of all nodes until with get the 'higest' // state possible Log(( "Connection %s state %s\n", Name.latin1(), StateName[CurrentState] )); CurrentState = Unknown; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { Log(( "-> Detect %s\n", it.current()->name() )); NodeState = it.current()->runtime()->detectState(); Log(( " state %s\n", StateName[NodeState] )); if( NodeState == Disabled || NodeState == IsUp ) { // max CurrentState = NodeState; break; } if( NodeState > CurrentState ) { // higher CurrentState = NodeState; } } } return CurrentState; } QString NodeCollection::setState( Action_t A, bool Force ) { QString msg; Action_t Actions[10]; int NoOfActions = 0; // get current state state( Force ); switch( A ) { case Disable : if( CurrentState < Disabled ) { // disabled CurrentState = Disabled; return QString(); } if( CurrentState == IsUp ) { Actions[NoOfActions++] = Down; Actions[NoOfActions++] = Deactivate; } else if( CurrentState == Available ) { Actions[NoOfActions++] = Deactivate; } Actions[NoOfActions++] = Disable; break; case Enable : // always possible -> detected state is new state Actions[NoOfActions++] = Enable; break; case Activate : if( ! Force ) { if( CurrentState >= Available ) { // already available return QString(); } if( CurrentState != Off ) { return qApp->translate( "System", "State should be off" ); } } Actions[NoOfActions++] = Activate; break; case Deactivate : if( ! Force ) { if( CurrentState < Off ) { // already inactive return QString(); } } if( CurrentState == IsUp ) { Actions[NoOfActions++] = Down; } Actions[NoOfActions++] = Deactivate; break; case Up : if( ! Force ) { if( CurrentState == IsUp ) { return QString(); } if( CurrentState < Off ) { return qApp->translate( "System", "State should at least be off" ); } } if( CurrentState == Off ) { Actions[NoOfActions++] = Activate; } Actions[NoOfActions++] = Up; break; case Down : if( ! Force ) { if( CurrentState < Available ) { // OK return QString(); } } Actions[NoOfActions++] = Down; break; } // send actions to all nodes Log(( "Action %s requires %d steps\n", ActionName[A], NoOfActions )); for( int i = 0 ; i < NoOfActions; i ++ ) { // setState recurses through the tree depth first msg = getToplevel()->runtime()->setState( this, Actions[i], Force ); if( ! msg.isEmpty() ) { return msg; } } return QString(); } // // // RuntimeInfo // // QString RuntimeInfo::setState( NodeCollection * NC, Action_t A, bool Force ) { QString M; RuntimeInfo * Deeper = nextNode(); if( Deeper ) { // first go deeper M = Deeper->setState( NC, A, Force ); if( ! M.isEmpty() ) return M; } // set my own state Log (( "-> Act upon %s\n", netNode()->name() )); M = setMyState( NC, A, Force ); Log (( " result %s\n", M.latin1() )); return M; } diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 8b3b4fe..50fb15a 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -1,470 +1,473 @@ #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <pwd.h> #include <qpixmap.h> #include <qdir.h> #include <qpe/qlibrary.h> #include <qpe/qpeapplication.h> #include <opie2/odebug.h> #include <qtopia/resource.h> #include "netnode.h" #include "resources.h" #define PLUGINDIR "plugins/networksettings2" #define ICONDIR "/pics/networksettings2/" // single resources instance TheNSResources * _NSResources = 0; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), ConnectionsMap() { _NSResources = this; detectCurrentUser(); // load available netnodes findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); // compile provides and needs lists { const char ** NeedsRun; QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); bool Done; for ( ; OuterIt.current(); ++OuterIt ) { // find needs list ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; ANetNode::NetNodeList & NNL = *(NNLP); // must iterate this way to avoid duplication pointers for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); InnerIt.current(); ++InnerIt ) { if( InnerIt.current() == OuterIt.current() ) // avoid recursive continue; const char ** Provides = InnerIt.current()->NetNode->provides(); NeedsRun = OuterIt.current()->NetNode->needs(); for( ; *NeedsRun; NeedsRun ++ ) { const char ** PRun; PRun = Provides; for( ; *PRun; PRun ++ ) { if( strcmp( *PRun, *NeedsRun ) == 0 ) { // inner provides what outer needs NNL.resize( NNL.size() + 1 ); NNL[NNL.size()-1] = InnerIt.current()->NetNode; Done = 1; // break from 2 loops break; } } } } OuterIt.current()->NetNode->setAlternatives( NNLP ); } } // define built in Node types to Description map addNodeType( "device", tr( "Network Device" ), tr( "<p>Devices that can handle IP packets</p>" ) ); addNodeType( "line", tr( "Character device" ), tr( "<p>Devices that can handle single bytes</p>" ) ); addNodeType( "connection", tr( "IP Connection" ), tr( "<p>Nodes that provide working IP connections</p>" ) ); addNodeType( "fullsetup", tr( "Connection Profile" ), tr( "<p>Fully configured connection profile</p>" ) ); addNodeType( "GPRS", tr( "Connection to GPRS device" ), tr( "<p>Connection to a GPRS capable device</p>" ) ); // get access to the system TheSystem = new System(); } TheNSResources::~TheNSResources( void ) { delete TheSystem; } void TheNSResources::addNodeType( const QString & ID, const QString & Name, const QString & Descr ) { if( NodeTypeNameMap[ID].isEmpty() ) { NodeTypeNameMap.insert( ID, Name ); NodeTypeDescriptionMap.insert( ID, Descr ); } } void TheNSResources::addSystemFile( const QString & ID, const QString & P, bool KDI ) { if( ! SystemFiles.find( ID ) ) { // new system file SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); } // else existed } void TheNSResources::busy( bool ) { /* if( B ) { ShowWait->show(); qApp->process } else { ShowWait->hide(); } */ } /** * Load all modules that are found in the path * @param path a directory that is scaned for any plugins that can be loaded * and attempts to load them */ void TheNSResources::findAvailableNetNodes(const QString &path){ Log(("Locate plugins in %s\n", path.latin1() )); QDir d(path); if(!d.exists()) return; QString lang = ::getenv("LANG"); // Don't want sym links d.setFilter( QDir::Files | QDir::NoSymLinks ); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; while ( (fi=it.current()) ) { if( fi->fileName().contains(".so")){ /* if loaded install translation */ if( loadNetNode(path + "/" + fi->fileName()) ) { + Log(( "Loading plugin %s\n", fi->fileName().latin1())); QTranslator *trans = new QTranslator(qApp); QString fn = QPEApplication::qpeDir()+ "/i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+ ".qm"; if( trans->load( fn ) ) qApp->installTranslator( trans ); else delete trans; + } else { + Log(( "Error loading plugin %s\n", fi->fileName().latin1())); } } ++it; } } // used to find unique connection number int TheNSResources::assignConnectionNumber( void ) { bool found = 1; for( int trial = 0; ; trial ++ ) { found = 1; for( QDictIterator<NodeCollection> it(ConnectionsMap); it.current(); ++it ) { if( it.current()->number() == trial ) { found = 0; break; } } if( found ) { Log(("Assign profile number %d\n", trial )); return trial; } } } /** * Attempt to load a function and resolve a function. * @param pluginFileName - the name of the file in which to attempt to load * @param resolveString - function pointer to resolve * @return true of loading is successful */ bool TheNSResources::loadNetNode( const QString &pluginFileName, const QString &resolveString){ QLibrary *lib = new QLibrary(pluginFileName); void * res = lib->resolve(resolveString); if( ! res ){ delete lib; return 0; } GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; // Try to get an object. QList<ANetNode> PNN; getNetNodeList( PNN ); if( PNN.isEmpty() ) { delete lib; return 0; } ANetNode * NNP; for( QListIterator<ANetNode> it(PNN); it.current(); ++it ) { NetNode_t * NN; NNP = it.current(); NN = new NetNode_t; NN->NetNode = NNP; NN->TheLibrary = lib; NN->NodeCountInLib = PNN.count(); // store mapping AllNodeTypes.insert( NN->NetNode->name(), NN ); } return 1; } QPixmap TheNSResources::getPixmap( const QString & QS ) { QPixmap P; QString S("networksettings2/"); S += QS; P = Resource::loadPixmap( S ); if( P.isNull() ) { Log(( "Cannot load %s\n", S.latin1() )); } return ( P.isNull() ) ? QPixmap() : P; } QString TheNSResources::tr( const char * s ) { return qApp->translate( "resource", s ); } const QString & TheNSResources::netNode2Name( const char * s ) { return NodeTypeNameMap[s]; } const QString & TheNSResources::netNode2Description( const char * s ) { return NodeTypeDescriptionMap[s]; } void TheNSResources::addConnection( NodeCollection * NC ) { ANetNodeInstance * NNI; ConnectionsMap.insert( NC->name(), NC ); // add (new) nodes to NodeList for( QListIterator<ANetNodeInstance> it(*NC); it.current(); ++it ) { NNI = it.current(); if( findNodeInstance( NNI->name() ) == 0 ) { // new item addNodeInstance( NNI ); } } } void TheNSResources::removeConnection( const QString & N ) { NodeCollection * NC = findConnection( N ); if( ! NC ) return; // delete netnodes in this connection ANetNodeInstance * NNI; for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { removeNodeInstance( NNI->name() ); } ConnectionsMap.remove( N ); } NodeCollection * TheNSResources::findConnection( const QString & S ) { return ConnectionsMap[ S ]; } NodeCollection * TheNSResources::getConnection( int nr ) { for( QDictIterator<NodeCollection> it(ConnectionsMap); it.current(); ++it ) { if( it.current()->number() == nr ) { return it.current(); } } return 0; } /* void TheNSResources::renumberConnections( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections NodeCollection::resetMaxNr(); for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); NC->setNumber( NC->maxConnectionNumber()+1 ); NC->setModified( 1 ); } } */ typedef struct EnvVars { char * Name; int Len; } EnvVar_t; #define AnEV(x) x, sizeof(x)-1 static EnvVar_t EV[] = { AnEV( "HOME" ), AnEV( "LOGNAME" ), AnEV( "USER" ), AnEV( "LD_LIBRARY_PATH" ), AnEV( "PATH" ), AnEV( "QTDIR" ), AnEV( "OPIEDIR" ), AnEV( "SHELL" ), { NULL, 0 } }; void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; CurrentUser.UserName = ""; CurrentUser.HomeDir = ""; if( getenv( "OPIEDIR" ) == 0 ) { // nothing known { // open proc dir and find all dirs in it QRegExp R("[0-9]+"); QDir ProcDir( "/proc" ); QFileInfo FI; QStringList EL = ProcDir.entryList( QDir::Dirs ); // print it out for ( QStringList::Iterator it = EL.begin(); it != EL.end(); ++it ) { if( R.match( (*it) ) >= 0 ) { QString S = ProcDir.path()+"/"+ (*it); S.append( "/exe" ); FI.setFile( S ); // get the link S = FI.readLink(); if( S.right( 8 ) == "/bin/qpe" ) { // found running qpe QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); break; } } } } if( QPEEnvFile.isEmpty() ) { // could not find qpe Log(("Could not find qpe\n" )); return; } // FI now contains path ProcDir to the cmd dir { char * Buf = 0; char TB[1024]; long BufSize = 0; int fd; int rd; fd = open( QPEEnvFile.latin1(), O_RDONLY ); if( fd < 0 ) { Log(("Could not open %s : %d\n", QPEEnvFile.latin1(), errno )); return; } while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { Buf = (char *)realloc( Buf, BufSize+rd ); memcpy( Buf+BufSize, TB, rd ); BufSize += rd; } char * Data = Buf; char * DataEnd = Data+BufSize-1; // get env items out of list while( Data < DataEnd ) { EnvVar_t * Run = EV; while( Run->Name ) { if( strncmp( Data, Run->Name, Run->Len ) == 0 && Data[Run->Len] == '=' ) { CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( Data ); if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { // put OPIEDIR in env putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); } else if( strcmp( Run->Name, "HOME" ) == 0 ) { CurrentUser.HomeDir = Data+5; } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { CurrentUser.UserName = Data+8; } break; } Run ++; } Data += strlen( Data )+1; } free( Buf ); if( ! CurrentUser.UserName.isEmpty() ) { // find user info struct passwd pwd; struct passwd * pwdres; if( getpwnam_r( CurrentUser.UserName.latin1(), &pwd, TB, sizeof(TB), &pwdres ) || pwdres == 0 ) { Log(("Could not determine user %s : %d\n", CurrentUser.UserName.latin1(), errno )); return; } CurrentUser.Uid = pwd.pw_uid; CurrentUser.Gid = pwd.pw_gid; } else{ CurrentUser.Uid = CurrentUser.Gid = -1; } } } else { char * X; QString S; EnvVar_t * Run = EV; while( Run->Name ) { if( ( X = getenv( Run->Name ) ) ) { Log(( "Env : %s = %s\n", Run->Name, X )); S.sprintf( "%s=%s", Run->Name, X ); CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( S.latin1() ); if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { CurrentUser.UserName = X; } else if( strcmp( Run->Name, "HOME" ) == 0 ) { CurrentUser.HomeDir = X; } // regulare env var } else { Log(("Could not determine %s\n", Run->Name )); } Run ++; } CurrentUser.Uid = getuid(); CurrentUser.Gid = getgid(); } } diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 634cd39..5d90286 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -1,143 +1,144 @@ #ifndef __RESOURCES__H #define __RESOURCES__H #include <qstring.h> #include <qdict.h> #include <qmap.h> #include <qlist.h> #include "netnode.h" #include "systemfile.h" #include "system.h" class QLibrary; class QPixmap; class ANetNode; class ANetNodeInstance; typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN ); typedef struct NetNode_S { ANetNode * NetNode; QLibrary * TheLibrary; long NodeCountInLib; } NetNode_t; class CurrentQPEUser { public : CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} inline bool known( void ) { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } QString UserName; QString HomeDir; int Uid; int Gid; QArray<char *> EnvList; }; typedef QDict<NetNode_t> Name2NetNode_t; typedef QDict<ANetNodeInstance > Name2Instance_t; typedef QDict<NodeCollection> Name2Connection_t; typedef QDict<SystemFile> Name2SystemFile_t; class TheNSResources { public : TheNSResources( void ); ~TheNSResources( ); // give busy feedback void busy( bool B ); System & system() { return *TheSystem; } int assignConnectionNumber(void); QPixmap getPixmap( const QString & Name ); Name2NetNode_t & netNodes( void ) { return AllNodeTypes; } bool netNodeExists( const QString & X ) { return AllNodeTypes.find(X)!=0; } ANetNode * findNetNode( const QString & N ) { NetNode_t * NNT = AllNodeTypes.find(N); return (NNT) ? NNT->NetNode : 0; } // define new plugin (=node) void addNodeType( const QString & ID, const QString & LongName, const QString & Description ); Name2SystemFile_t & systemFiles( void ) { return SystemFiles; } void addSystemFile( const QString & ID, const QString & P, bool KDI ); ANetNodeInstance * createNodeInstance( const QString & S ) { ANetNodeInstance * NNI = 0; + printf( "Find node type %s\n", S.latin1() ); NetNode_t * NNT = AllNodeTypes[S]; if( ! NNT ) { return 0; } NNI = NNT->NetNode->createInstance(); NNI->initialize(); return NNI; } Name2Instance_t & netNodeInstances( void ) { return AllNodes; } void addNodeInstance( ANetNodeInstance * I ) { AllNodes.insert( I->name(), I ); } void removeNodeInstance( const QString & N ) { AllNodes.remove( N );} ANetNodeInstance * findNodeInstance( const QString & S ) - { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; } + { return AllNodes[S]; } const QString & netNode2Name( const char * Type ); const QString & netNode2Description( const char * Type ); void addConnection( NodeCollection * NC ); void removeConnection( const QString & N ); NodeCollection * findConnection( const QString & N ); NodeCollection * getConnection( int nr ); Name2Connection_t & connections( void ) { return ConnectionsMap; } inline bool userKnown( void ) { return CurrentUser.known(); } CurrentQPEUser & currentUser( void ) { return CurrentUser; } private : void detectCurrentUser( void ); QString tr( const char * path ); void findAvailableNetNodes( const QString &path ); bool loadNetNode( const QString &pluginFileName, const QString &resolveString = "create_plugin"); QMap< QString, QString> NodeTypeNameMap; QMap< QString, QString> NodeTypeDescriptionMap; Name2Connection_t ConnectionsMap; System * TheSystem; Name2SystemFile_t SystemFiles; // all node type classes Name2NetNode_t AllNodeTypes; // all nodes Name2Instance_t AllNodes; CurrentQPEUser CurrentUser; }; extern TheNSResources * _NSResources; #define NSResources _NSResources #endif |