summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.cpp37
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.h48
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnodeinterface.h18
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp171
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.h60
5 files changed, 116 insertions, 218 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp
index f8f2d1e..f00e0b3 100644
--- a/noncore/settings/networksettings2/networksettings2/netnode.cpp
+++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp
@@ -143,9 +143,13 @@ NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() {
143 AssignedInterface = 0; 143 AssignedInterface = 0;
144 Number = -1;
145 Done = 0;
144} 146}
145 147
146NodeCollection::NodeCollection( QTextStream & TS ) : 148NodeCollection::NodeCollection( QTextStream & TS, bool & Dangling ) :
147 QList<ANetNodeInstance>() { 149 QList<ANetNodeInstance>() {
148 long idx; 150 long idx;
149 bool InError = 0;
150 QString S, A, N; 151 QString S, A, N;
152
153 Number = -1;
154 Done = 0;
151 IsModified = 0; 155 IsModified = 0;
@@ -157,2 +161,4 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
157 161
162 Dangling = 0; // by default node collection is ok
163
158 do { 164 do {
@@ -160,6 +166,2 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
160 if( S.isEmpty() ) { 166 if( S.isEmpty() ) {
161 if( InError ) {
162 // remove all nodes
163 clear();
164 }
165 // empty line 167 // empty line
@@ -183,3 +185,3 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
183 Log(( "Find node %s : %p\n", N.latin1(), NNI )); 185 Log(( "Find node %s : %p\n", N.latin1(), NNI ));
184 if( NNI && ! InError ) { 186 if( NNI ) {
185 append( NNI ); 187 append( NNI );
@@ -187,3 +189,7 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
187 // could not find a node type -> collection invalid 189 // could not find a node type -> collection invalid
188 InError = 1; 190 Log(( "Node %s missing -> connection dangling\n",
191 N.latin1() ));
192 // create placeholder for this dangling NNI
193 NNI = new ErrorNNI( N );
194 Dangling = 1;
189 } 195 }
@@ -196,3 +202,2 @@ NodeCollection::NodeCollection( QTextStream & TS ) :
196 202
197
198NodeCollection::~NodeCollection( void ) { 203NodeCollection::~NodeCollection( void ) {
@@ -231,6 +236,7 @@ ANetNodeInstance * NodeCollection::getToplevel( void ) {
231 NNI = it.current(); 236 NNI = it.current();
232 if( NNI->nodeClass()->isToplevel() ) 237 if( NNI->nodeClass()->isToplevel() ) {
233 break; 238 return NNI;
239 }
234 } 240 }
235 return NNI; 241 return 0;
236} 242}
@@ -243,6 +249,7 @@ ANetNodeInstance * NodeCollection::findByName( const QString & S ) {
243 NNI = it.current(); 249 NNI = it.current();
244 if( NNI->name() == S ) 250 if( NNI->name() == S ) {
245 break; 251 return NNI;
252 }
246 } 253 }
247 return NNI; 254 return 0;
248} 255}
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h
index 4626381..151d546 100644
--- a/noncore/settings/networksettings2/networksettings2/netnode.h
+++ b/noncore/settings/networksettings2/networksettings2/netnode.h
@@ -321,2 +321,4 @@ protected :
321 bool IsModified; 321 bool IsModified;
322 // true if this nodeinstance was just created (and not
323 // loaded from file
322 bool IsNew; 324 bool IsNew;
@@ -327,2 +329,42 @@ protected :
327 329
330class ErrorNNI: public ANetNodeInstance {
331
332public:
333
334 ErrorNNI( const QString & _Name ) : ANetNodeInstance( 0 ) {
335 setName( _Name.latin1() );
336 }
337
338 RuntimeInfo * runtime( void ) {
339 return 0;
340 }
341
342 // create edit widget under parent
343 QWidget * edit( QWidget * parent ) {
344 return 0;
345 }
346
347 // is given data acceptable
348 QString acceptable( void ) {
349 return QString();
350 }
351
352 // get data from GUI and store in node
353 void commit( void ) {
354 }
355
356 // returns node specific data -> only useful for 'buddy'
357 void * data( void ) {
358 return 0;
359 }
360
361protected :
362
363 void setSpecificAttribute( QString & , QString & ) {
364 }
365
366 void saveSpecificAttribute( QTextStream & ) {
367 }
368};
369
328class RuntimeInfo : public QObject { 370class RuntimeInfo : public QObject {
@@ -470,3 +512,3 @@ public :
470 NodeCollection( void ); 512 NodeCollection( void );
471 NodeCollection( QTextStream & TS ); 513 NodeCollection( QTextStream & TS, bool & Dangling );
472 ~NodeCollection( void ); 514 ~NodeCollection( void );
@@ -587,5 +629,5 @@ private :
587 // index in listbox 629 // index in listbox
588 int Index; 630 int Index;
589 bool IsModified; 631 bool IsModified;
590 int Done; 632 int Done;
591 633
diff --git a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h
index 34f3bb5..06d1548 100644
--- a/noncore/settings/networksettings2/networksettings2/netnodeinterface.h
+++ b/noncore/settings/networksettings2/networksettings2/netnodeinterface.h
@@ -80,4 +80,14 @@ struct NS2PrivateFactory<Opie::Core::Typelist<Node, Tail> > {
80 80
81class NetNodeInterface : public QUnknownInterface {
82
83public :
84
85 virtual QRESULT queryInterface( const QUuid& uuid,
86 QUnknownInterface **iface ) = 0;
87
88 virtual void create_plugin( QList<ANetNode> & PNN ) = 0;
89};
90
81template<class Node> 91template<class Node>
82struct NetNodeInterface : public QUnknownInterface { 92struct NetNodeInterface_T : public NetNodeInterface {
83 93
@@ -109,4 +119,4 @@ struct NetNodeInterface : public QUnknownInterface {
109template<class Node, class Tail> 119template<class Node, class Tail>
110struct NetNodeInterface<Opie::Core::Typelist<Node, Tail> > 120struct NetNodeInterface_T<Opie::Core::Typelist<Node, Tail> >
111 : public QUnknownInterface { 121 : public NetNodeInterface {
112 122
@@ -127,3 +137,3 @@ struct NetNodeInterface<Opie::Core::Typelist<Node, Tail> >
127 void create_plugin( QList<ANetNode> & PNN ) { 137 void create_plugin( QList<ANetNode> & PNN ) {
128 NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugin( PNN ); 138 NS2PrivateFactory<Opie::Core::Typelist<Node,Tail> >::createPlugins( PNN );
129 } 139 }
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp
index 79d41ea..3479abb 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.cpp
+++ b/noncore/settings/networksettings2/networksettings2/resources.cpp
@@ -27,3 +27,3 @@ TheNSResources * _NSResources = 0;
27TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), 27TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
28 ConnectionsMap() { 28 ConnectionsMap(), DanglingConnectionsMap() {
29 29
@@ -35,46 +35,2 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
35 35
36#ifdef MYPLUGIN
37
38 findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR );
39
40 // compile provides and needs lists
41 { const char ** NeedsRun;
42 QDictIterator<NetNode_t> OuterIt( AllNodeTypes );
43 bool Done;
44
45 for ( ; OuterIt.current(); ++OuterIt ) {
46 // find needs list
47 ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList;
48 ANetNode::NetNodeList & NNL = *(NNLP);
49
50 // must iterate this way to avoid duplication pointers
51 for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes );
52 InnerIt.current(); ++InnerIt ) {
53 if( InnerIt.current() == OuterIt.current() )
54 // avoid recursive
55 continue;
56
57 const char ** Provides = InnerIt.current()->NetNode->provides();
58 NeedsRun = OuterIt.current()->NetNode->needs();
59
60 for( ; *NeedsRun; NeedsRun ++ ) {
61 const char ** PRun;
62 PRun = Provides;
63 for( ; *PRun; PRun ++ ) {
64 if( strcmp( *PRun, *NeedsRun ) == 0 ) {
65 // inner provides what outer needs
66 NNL.resize( NNL.size() + 1 );
67 NNL[NNL.size()-1] = InnerIt.current()->NetNode;
68 Done = 1; // break from 2 loops
69 break;
70 }
71 }
72 }
73 }
74 OuterIt.current()->NetNode->setAlternatives( NNLP );
75 }
76 }
77
78#else
79
80 Plugins = 0; 36 Plugins = 0;
@@ -121,4 +77,2 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
121 77
122#endif
123
124 // define built in Node types to Description map 78 // define built in Node types to Description map
@@ -142,3 +96,2 @@ TheNSResources::~TheNSResources( void ) {
142 96
143#ifndef MYPLUGINS
144 if( Plugins ) { 97 if( Plugins ) {
@@ -147,3 +100,2 @@ TheNSResources::~TheNSResources( void ) {
147 } 100 }
148#endif
149 delete TheSystem; 101 delete TheSystem;
@@ -181,95 +133,2 @@ void TheNSResources::busy( bool ) {
181 133
182#ifdef MYPLUGIN
183/**
184 * Load all modules that are found in the path
185 * @param path a directory that is scaned for any plugins that can be loaded
186 * and attempts to load them
187 */
188void TheNSResources::findAvailableNetNodes(const QString &path){
189
190 Log(("Locate plugins in %s\n", path.latin1() ));
191 QDir d(path);
192 if(!d.exists())
193 return;
194
195 QString lang = ::getenv("LANG");
196
197 // Don't want sym links
198 d.setFilter( QDir::Files | QDir::NoSymLinks );
199 const QFileInfoList *list = d.entryInfoList();
200 QFileInfoListIterator it( *list );
201 QFileInfo *fi;
202
203 while ( (fi=it.current()) ) {
204
205 if( fi->fileName().contains(".so")){
206 /* if loaded install translation */
207 if( loadNetNode(path + "/" + fi->fileName()) ) {
208 Log(( "Loading plugin %s\n", fi->fileName().latin1()));
209 QTranslator *trans = new QTranslator(qApp);
210 QString fn = QPEApplication::qpeDir()+
211 "/i18n/"+lang+"/"+
212 fi->fileName().left( fi->fileName().find(".") )+
213 ".qm";
214
215 if( trans->load( fn ) )
216 qApp->installTranslator( trans );
217 else
218 delete trans;
219 } else {
220 Log(( "Error loading plugin %s\n", fi->fileName().latin1()));
221 }
222 }
223 ++it;
224 }
225}
226
227/**
228 * Attempt to load a function and resolve a function.
229 * @param pluginFileName - the name of the file in which to attempt to load
230 * @param resolveString - function pointer to resolve
231 * @return true of loading is successful
232 */
233bool TheNSResources::loadNetNode(
234 const QString &pluginFileName, const QString &resolveString){
235
236 QLibrary *lib = new QLibrary(pluginFileName);
237 void * res = lib->resolve(resolveString);
238 if( ! res ){
239 delete lib;
240 return 0;
241 }
242
243 GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res;
244
245 // Try to get an object.
246 QList<ANetNode> PNN;
247
248 getNetNodeList( PNN );
249 if( PNN.isEmpty() ) {
250 delete lib;
251 return 0;
252 }
253
254 ANetNode * NNP;
255 for( QListIterator<ANetNode> it(PNN);
256 it.current();
257 ++it ) {
258 NetNode_t * NN;
259
260 NNP = it.current();
261 NN = new NetNode_t;
262 NN->NetNode = NNP;
263 NN->TheLibrary = lib;
264 NN->NodeCountInLib = PNN.count();
265
266 // store mapping
267 AllNodeTypes.insert( NN->NetNode->name(), NN );
268 }
269
270 return 1;
271}
272
273#else
274
275void TheNSResources::findAvailableNetNodes( void ){ 134void TheNSResources::findAvailableNetNodes( void ){
@@ -295,2 +154,3 @@ void TheNSResources::findAvailableNetNodes( void ){
295 OPluginLoader::List allplugins = Plugins->filtered(); 154 OPluginLoader::List allplugins = Plugins->filtered();
155 QString lang = ::getenv("LANG");
296 156
@@ -306,3 +166,3 @@ void TheNSResources::findAvailableNetNodes( void ){
306 Log(( "Plugin %s from %s does not support proper interface\n", 166 Log(( "Plugin %s from %s does not support proper interface\n",
307 it->name().latin1(), it->path().latin1() )); 167 (*it).name().latin1(), (*it).path().latin1() ));
308 continue; 168 continue;
@@ -317,3 +177,3 @@ void TheNSResources::findAvailableNetNodes( void ){
317 Log(( "Plugin %s from %s does offer any nodes\n", 177 Log(( "Plugin %s from %s does offer any nodes\n",
318 it->name().latin1(), it->path().latin1() )); 178 (*it).name().latin1(), (*it).path().latin1() ));
319 delete interface; 179 delete interface;
@@ -326,3 +186,3 @@ void TheNSResources::findAvailableNetNodes( void ){
326 ++it ) { 186 ++it ) {
327 AllNodeTypes.insert( it->current()->name(), it->current() ); 187 AllNodeTypes.insert( it.current()->name(), it.current() );
328 } 188 }
@@ -333,3 +193,3 @@ void TheNSResources::findAvailableNetNodes( void ){
333 QString fn = QPEApplication::qpeDir()+ 193 QString fn = QPEApplication::qpeDir()+
334 "/i18n/"+lang+"/"+ it->name() + ".qm"; 194 "/i18n/"+lang+"/"+ (*it).name() + ".qm";
335 195
@@ -343,4 +203,2 @@ void TheNSResources::findAvailableNetNodes( void ){
343 203
344#endif
345
346// used to find unique connection number 204// used to find unique connection number
@@ -389,5 +247,10 @@ const QString & TheNSResources::netNode2Description( const char * s ) {
389 247
390void TheNSResources::addConnection( NodeCollection * NC ) { 248void TheNSResources::addConnection( NodeCollection * NC, bool Dangling ) {
391 ANetNodeInstance * NNI; 249 ANetNodeInstance * NNI;
392 ConnectionsMap.insert( NC->name(), NC ); 250 if( Dangling ) {
251 DanglingConnectionsMap.insert( NC->name(), NC );
252 } else {
253 ConnectionsMap.insert( NC->name(), NC );
254 }
255
393 // add (new) nodes to NodeList 256 // add (new) nodes to NodeList
@@ -414,5 +277,11 @@ void TheNSResources::removeConnection( const QString & N ) {
414 } 277 }
415 ConnectionsMap.remove( N ); 278 if( ConnectionsMap.find( N ) ) {
279 ConnectionsMap.remove( N );
280 } else {
281 DanglingConnectionsMap.remove( N );
282 }
283
416} 284}
417 285
286// dangling connections are filtered out
418NodeCollection * TheNSResources::findConnection( const QString & S ) { 287NodeCollection * TheNSResources::findConnection( const QString & S ) {
diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h
index 421a433..b27cda1 100644
--- a/noncore/settings/networksettings2/networksettings2/resources.h
+++ b/noncore/settings/networksettings2/networksettings2/resources.h
@@ -40,17 +40,3 @@ public :
40 40
41#ifdef MYPLUGIN
42
43typedef struct NetNode_S {
44 ANetNode * NetNode;
45 QLibrary * TheLibrary;
46 long NodeCountInLib;
47} NetNode_t;
48typedef QDict<NetNode_t> Name2NetNode_t;
49
50#else
51
52typedef QDict<ANetNode> Name2NetNode_t; 41typedef QDict<ANetNode> Name2NetNode_t;
53
54#endif
55
56typedef QDict<ANetNodeInstance > Name2Instance_t; 42typedef QDict<ANetNodeInstance > Name2Instance_t;
@@ -79,8 +65,2 @@ public :
79 { return AllNodeTypes.find(X)!=0; } 65 { return AllNodeTypes.find(X)!=0; }
80#ifdef MYPLUGIN
81 ANetNode * findNetNode( const QString & N )
82 { NetNode_t * NNT = AllNodeTypes.find(N);
83 return (NNT) ? NNT->NetNode : 0;
84 }
85#else
86 ANetNode * findNetNode( const QString & N ) 66 ANetNode * findNetNode( const QString & N )
@@ -88,3 +68,2 @@ public :
88 } 68 }
89#endif
90 // define new plugin (=node) 69 // define new plugin (=node)
@@ -101,17 +80,11 @@ public :
101 ANetNodeInstance * createNodeInstance( const QString & S ) 80 ANetNodeInstance * createNodeInstance( const QString & S )
102 { ANetNodeInstance * NNI = 0; 81 { ANetNode * NN = findNetNode( S );
103 printf( "Find node type %s\n", S.latin1() ); 82
104#ifdef MYPLUGIN 83 Log(( "Find node type %s : %p\n", S.latin1(), NN ));
105 NetNode_t * NNT = AllNodeTypes[S]; 84
106 if( ! NNT ) { 85 if( NN == 0 )
107 return 0; 86 // type of this instance not found
108 }
109 NNI = NNT->NetNode->createInstance();
110#else
111 ANetNode * NNT = AllNodeTypes[S];
112 if( ! NNT ) {
113 return 0; 87 return 0;
114 } 88
115 NNI = NNT->createInstance(); 89 ANetNodeInstance * NNI = NN->createInstance();
116#endif
117 NNI->initialize(); 90 NNI->initialize();
@@ -132,3 +105,3 @@ public :
132 105
133 void addConnection( NodeCollection * NC ); 106 void addConnection( NodeCollection * NC, bool Dangling );
134 void removeConnection( const QString & N ); 107 void removeConnection( const QString & N );
@@ -138,2 +111,4 @@ public :
138 { return ConnectionsMap; } 111 { return ConnectionsMap; }
112 Name2Connection_t & danglingConnections( void )
113 { return ConnectionsMap; }
139 114
@@ -149,10 +124,3 @@ private :
149 124
150#ifdef MYPLUGIN
151 void findAvailableNetNodes( const QString &path );
152 bool loadNetNode(
153 const QString &pluginFileName,
154 const QString &resolveString = "create_plugin");
155#else
156 void findAvailableNetNodes( void ); 125 void findAvailableNetNodes( void );
157#endif
158 126
@@ -160,3 +128,7 @@ private :
160 QMap< QString, QString> NodeTypeDescriptionMap; 128 QMap< QString, QString> NodeTypeDescriptionMap;
129 // list of connections that are valid
161 Name2Connection_t ConnectionsMap; 130 Name2Connection_t ConnectionsMap;
131 // list of connection configurations that are not valid
132 // e.g. because plugins are missing
133 Name2Connection_t DanglingConnectionsMap;
162 System * TheSystem; 134 System * TheSystem;
@@ -172,6 +144,4 @@ private :
172 144
173#ifndef MYPLUGIN
174 Opie::Core::OPluginLoader * Plugins; 145 Opie::Core::OPluginLoader * Plugins;
175 Opie::Core::OPluginManager * PluginManager; 146 Opie::Core::OPluginManager * PluginManager;
176#endif
177 147