Difference between revisions of "FindingApplications"

From Nsnam
Jump to: navigation, search
 
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
+
Sometimes, you may want to find an application of a given type on a node.  The <code>Node</code> objects provides basic access to do this, and the <code>TypeId</code> mechanism the ability to identify the application.  If the application objects have <code>TypeId</code> definitions, then this simple loop will find an application:
Sometimes, you may want to find an application of a given type on a node.  The @@Node@@ objects provides basic access to do this, and the @@TypeId@@ mechanism the ability to identify the application.  If the application objects have @@TypeId@@s, then this simple loop will find an application:
+
  
 
<code><pre>
 
<code><pre>
Line 18: Line 17:
 
</pre></code>
 
</pre></code>
  
Note the specific syntax of the cast---the template is of the pointer, note a @@Ptr@@.
+
Note the specific syntax of the cast---the template is of the pointer, not a <code>Ptr</code>.
  
 
[[Category:Samples]]
 
[[Category:Samples]]

Latest revision as of 21:21, 26 June 2008

Sometimes, you may want to find an application of a given type on a node. The Node objects provides basic access to do this, and the TypeId mechanism the ability to identify the application. If the application objects have TypeId definitions, then this simple loop will find an application:

  Ptr<Application> app;
  Ptr<MyApp> myapp = 0;
  for (uint32_t x = 0; x < node->GetNApplications(); x++) {
    app = node->GetApplication(x);
    if (app->GetInstanceTypeId() == MyApp::GetTypeId()) {
      myapp = dynamic_cast<MyApp *> (PeekPointer(app));
      break;
    }
  }

  if (myapp != 0) {
    // Do something MyApp specific with it...
  }

Note the specific syntax of the cast---the template is of the pointer, not a Ptr.