OverSim
OverlayAccess.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef __OVERLAY_ACCESS_H__
25 #define __OVERLAY_ACCESS_H__
26 
27 
28 #include <omnetpp.h>
29 
30 #include <BaseOverlay.h>
31 #include <NotificationBoard.h>
32 
37 {
38 public:
39 
40  BaseOverlay* get
41  (cModule* refMod)
42  {
43  // obtains the overlay related to the module, taking in account the index in case of SMOHs
44  BaseOverlay *overlay = NULL;
45  cModule *tmpMod = refMod;
46  cModule *tmpParent = NULL; // parent of tmpMod
47 
48  // go up from refMod until we get a NotificationBoard module, then we're at root
49  // this will fail if the overlay is not in a container module!
50  while (true) {
51  tmpParent = tmpMod->getParentModule(); // get parent
52  // search for a "notificationBoard" module
53  cModule *notBoard = tmpParent->getSubmodule("notificationBoard");
54  // is this a real NotificationBoard? then we're at root
55  if (dynamic_cast<NotificationBoard*>(notBoard) != NULL) break;
56  tmpMod = tmpParent; // else keep going up
57  if (!tmpParent) throw cRuntimeError("OverlayAccess::get(): Overlay module not found!");
58  }
59  // get the overlay container, with the proper index
60  cModule *overlayContainer = tmpParent->getSubmodule("overlay", tmpMod->getIndex());
61  overlay = dynamic_cast<BaseOverlay*>
62  (overlayContainer->gate("appIn")->getNextGate()->getOwnerModule()); // get the contained overlay module
63 
64  if (!overlay) throw cRuntimeError("OverlayAccess::get(): Overlay module not found!");
65 
66  return overlay;
67  }
68 };
69 
70 #endif