00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "stdafx.h"
00023 #include <Console.h>
00024 #include <Formatter.h>
00025 #include "BON2Component.h"
00026
00027 namespace BON
00028 {
00029
00030
00031
00032
00033
00034
00035
00036 Component::Component()
00037 : m_bIsInteractive( false )
00038 {
00039 }
00040
00041 Component::~Component()
00042 {
00043 if ( m_project ) {
00044 m_project->finalizeObjects();
00045 finalize( m_project );
00046 m_project = NULL;
00047 }
00048 }
00049
00050
00051
00052
00053
00054 void Component::initialize( Project& project )
00055 {
00056 }
00057
00058 static CString operator+(const CString& A, const std::string& B)
00059 {
00060 return A + B.c_str();
00061 }
00062
00063 static CString MakeHyperlink(BON::Object& obj)
00064 {
00065 return GMEConsole::Formatter::MakeObjectHyperlink(obj->getName().c_str(), obj->getID().c_str());
00066 }
00067
00068 void Component::ProcessDiagram(BON::Model& diagram)
00069 {
00070 using namespace GMEConsole;
00071 ASSERT(diagram->getObjectMeta().name() == "NetDiagram");
00072
00073 Console::Out::WriteLine(CString("Network ") + diagram->getName());
00074
00075 std::set<BON::FCO> childModels = diagram->getChildFCOs("NetDiagram");
00076 for (std::set<BON::FCO>::iterator it = childModels.begin(); it != childModels.end(); it++) {
00077 ProcessDiagram(BON::Model(*it));
00078 }
00079
00080 childModels = diagram->getChildFCOs("Router");
00081 for (std::set<BON::FCO>::iterator it = childModels.begin(); it != childModels.end(); it++) {
00082 ProcessRouter(BON::Model(*it));
00083 }
00084
00085 std::set<MON::Atom> atoms = diagram->getProject()->getProjectMeta().atoms();
00086 for (std::set<MON::Atom>::iterator it = atoms.begin(); it != atoms.end(); it++) {
00087 Console::Out::WriteLine(CString(it->name().c_str()));
00088 std::set<MON::ConnectionEnd> target = it->connectionEnds();
00089 for (std::set<MON::ConnectionEnd>::iterator it2 = target.begin(); it2 != target.end(); it2++) {
00090
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 std::set<BON::FCO> childFCOs = diagram->getChildFCOs();
00101 for (std::set<BON::FCO>::iterator it = childFCOs.begin(); it != childFCOs.end(); it++) {
00102 if (BON::Reference(*it) && (*it)->getObjectMeta().name() == "RouterRef") {
00103 BON::Reference ref = *it;
00104 Console::Out::WriteLine(CString("RouterRef ") +
00105 MakeHyperlink(ref) + "(" + MakeHyperlink(ref->getReferred()) + ")");
00106 }
00107 }
00108
00109
00110 std::set<BON::Set> childSets = diagram->getChildSets();
00111 for (std::set<BON::Set>::iterator it = childSets.begin(); it != childSets.end(); it++) {
00112 if ((*it)->getObjectMeta().name() == "Administrator") {
00113 BON::Set admin = *it;
00114 std::set<BON::FCO> members = admin->getMembers();
00115 Console::Out::WriteLine(CString("Members of ") + admin->getName() + ": ");
00116 for (std::set<BON::FCO>::iterator it2 = members.begin(); it2 != members.end(); it2++) {
00117 Console::Out::WriteLine(CString(" ") + (*it2)->getName());
00118 }
00119 }
00120 }
00121 Console::Out::WriteLine(CString());
00122 }
00123
00124 void Component::ProcessRouter(BON::Model& router) {
00125 using namespace GMEConsole;
00126 std::string metaName = router->getObjectMeta().name();
00127 ASSERT(router->getObjectMeta().name() == "Router");
00128
00129 Console::Out::WriteLine(CString(" Router ") + MakeHyperlink(router));
00130
00131
00132 std::set<BON::Atom> atoms = router->getChildAtoms();
00133 for (std::set<BON::Atom>::iterator it = atoms.begin(); it != atoms.end(); it++) {
00134 if ((*it)->getObjectMeta().name() == "Port") {
00135 BON::Atom port = *it;
00136
00137 std::string iftype = port->getAttribute("IFType")->getStringValue();
00138 int ifspeed = port->getAttribute("IFSpeed")->getIntegerValue();
00139 std::string ipaddr = port->getAttribute("IPAddress")->getStringValue();
00140 Console::Out::WriteLine(CString(" Port ") + MakeHyperlink(port) +
00141 "(" + iftype + "; " + CComVariant(ifspeed) + "Kbps), Addr: " + ipaddr );
00142
00143 std::set<BON::Connection> conns = port->getConnLinks();
00144 for (std::set<BON::Connection>::iterator it2 = conns.begin(); it2 != conns.end(); it2++) {
00145 BON::ConnectionEnd other;
00146 if ((*it2)->getDst() == *it) {
00147 other = (*it2)->getSrc();
00148 } else {
00149 other = (*it2)->getDst();
00150 }
00151 if (BON::FCO(other)) {
00152 BON::FCO otherFCO(other);
00153 Console::Out::WriteLine(CString(" Connected to ") +
00154 otherFCO->getObjectMeta().name() + " " + MakeHyperlink(otherFCO));
00155 }
00156 }
00157 }
00158 }
00159
00160 }
00161
00162
00163
00164
00165
00166
00167 void Component::finalize( Project& project )
00168 {
00169
00170
00171 }
00172
00173
00174
00175
00176
00177 void Component::invoke( Project& project, const std::set<FCO>& setModels, long lParam )
00178 {
00179 #ifdef SUPPORT_OLD_INVOKE
00180 Object focus;
00181 invokeEx( project, focus, setModels, lParam );
00182 #else
00183 if ( m_bIsInteractive )
00184 AfxMessageBox("This BON2 Component does not support the obsolete invoke mechanism!");
00185 #endif
00186 }
00187
00188
00189
00190
00191
00192 void Component::invokeEx( Project& project, FCO& currentFCO, const std::set<FCO>& setSelectedFCOs, long lParam )
00193 {
00194 #ifdef GME_ADDON
00195 project->setAutoCommit( false);
00196 #endif
00197 using namespace GMEConsole;
00198 Console::Out::WriteLine("Interpreter started...");
00199
00200 Console::Out::WriteLine(CString("Router list for network ") + project->getRootFolder()->getName());
00201 std::set<BON::Model> rootModels = project->getRootFolder()->getChildModels();
00202 for (std::set<BON::Model>::iterator it = rootModels.begin(); it != rootModels.end(); it++) {
00203 if ((*it)->getObjectMeta().name()== "NetDiagram") {
00204 ProcessDiagram(BON::Model(*it));
00205 }
00206 }
00207 std::set<BON::Folder> folders = project->getRootFolder()->getChildFolders();
00208 for (std::set<BON::Folder>::iterator it = folders.begin(); it != folders.end(); it++) {
00209 std::set<BON::Model> models = (*it)->getChildModels();
00210 for (std::set<BON::Model>::iterator it2 = models.begin(); it2 != models.end(); it2++) {
00211 if ((*it2)->getObjectMeta().name()== "NetDiagram") {
00212 ProcessDiagram(BON::Model(*it2));
00213 }
00214 }
00215 }
00216
00217 Console::Out::WriteLine("Interpreter completed...");
00218 }
00219
00220
00221
00222
00223
00224 void Component::objectInvokeEx( Project& project, Object& currentObject, const std::set<Object>& setSelectedObjects, long lParam )
00225 {
00226 if ( m_bIsInteractive )
00227 AfxMessageBox("This BON2 Component does not support objectInvokeEx method!");
00228 }
00229
00230
00231
00232
00233 Util::Variant Component::getParameter( const std::string& strName )
00234 {
00235
00236
00237
00238 return Util::Variant();
00239 }
00240
00241 void Component::setParameter( const std::string& strName, const Util::Variant& varValue )
00242 {
00243
00244
00245 }
00246
00247 #ifdef GME_ADDON
00248
00249
00250
00251
00252 void Component::globalEventPerformed( globalevent_enum event )
00253 {
00254
00255
00256 }
00257
00258
00259
00260
00261 void Component::objectEventPerformed( Object& object, unsigned long event, VARIANT v )
00262 {
00263
00264
00265 }
00266
00267 #endif // GME_ADDON
00268
00269 };
00270