00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include<iostream>
00032 #include "clsap.h"
00033 #include "module.h"
00034 #include "node-core.h"
00035
00036 #include "deprecated.h"
00037
00038
00039
00040
00041 static class ClSAPClass : public TclClass {
00042 public:
00043 ClSAPClass() : TclClass("ConnectorTrace/ClSAP") {}
00044 TclObject* create(int, const char*const*) {
00045 return (new ClSAP());
00046 }
00047 } class_clsap;
00048
00049
00050
00051
00052 ClSAP::ClSAP() : ConnectorTrace(), pluginPtr_(0), nodeCorePtr_(0)
00053 {
00054 depthNC_ = DEFAULTDEPTH;
00055 bind("depthToNC_", &depthNC_);
00056 depthP_ = DEFAULTDEPTH;
00057 bind("depthToP_", &depthP_);
00058 }
00059
00060 ClSAP::~ClSAP()
00061 {
00062
00063
00064 }
00065
00066 int ClSAP::command(int argc, const char* const* argv)
00067 {
00068 Tcl& tcl = Tcl::instance();
00069 if (argc==3)
00070 {
00071
00072
00073
00074 if (strcasecmp(argv[1],"module")==0)
00075 {
00076 Module *module = (Module*)TclObject::lookup(argv[2]);
00077 if (pluginPtr_!=0)
00078 {
00079 tcl.resultf("Error ClSAP cmd = %s: a module is already installed", argv[1]);
00080 return (TCL_ERROR);
00081 }
00082 pluginPtr_ = module;
00083 return (TCL_OK);
00084 }
00085 if (strcasecmp(argv[1],"nodecore")==0)
00086 {
00087 NodeCore *nodecore = (NodeCore*)TclObject::lookup(argv[2]);
00088 if (nodeCorePtr_!=0)
00089 {
00090 tcl.resultf("Error ClSAP cmd = %s: a nodecore is already installed", argv[1]);
00091 return (TCL_ERROR);
00092 }
00093 nodeCorePtr_ = nodecore;
00094 return (TCL_OK);
00095 }
00096 }
00097 return ConnectorTrace::command(argc, argv);
00098 }
00099
00100
00101 void ClSAP::sendModule(ClMessage* m, double delay)
00102 {
00103
00104 if (pluginPtr_==0)
00105 {
00106 fprintf(stderr, "Error, ClSAP.sendModule: module not yet installed\n");
00107 exit(1);
00108 }
00109 m->direction(TOMODULE);
00110 if(delay > 0)
00111 {
00112 Scheduler::instance().schedule(this, m, delay);
00113 }
00114 else
00115 {
00116
00117 if (depthP_ >= m->verbosity())
00118 trace(m);
00119 RUN_DEPRECATED_OR_NEW_VIRTUAL_METHOD(pluginPtr_->crLayCommand(m), pluginPtr_->recvAsyncClMsg(m));
00120 }
00121 }
00122
00123 void ClSAP::sendSynchronousModule(ClMessage* m)
00124 {
00125
00126 if (pluginPtr_==0)
00127 {
00128 fprintf(stderr, "Error, ClSAP.sendModule: module not yet installed\n");
00129 exit(1);
00130 }
00131 m->direction(TOMODULE);
00132 if (depthP_ >= m->verbosity())
00133 traceSync(m);
00134 RUN_DEPRECATED_OR_NEW_VIRTUAL_METHOD(pluginPtr_->crLaySynchronousCommand(m), pluginPtr_->recvSyncClMsg(m));
00135 m->direction(TONODECORE);
00136 if (depthNC_ >= m->verbosity())
00137 traceSync(m);
00138 }
00139
00140 void ClSAP::sendClLayer(ClMessage* m, double delay)
00141 {
00142
00143 if (nodeCorePtr_==0)
00144 {
00145 fprintf(stderr, "Error, ClSAP.sendClModule: nodeCorePtr not yet installed\n");
00146 exit(1);
00147 }
00148 m->direction(TONODECORE);
00149 if (depthNC_ >= m->verbosity())
00150 trace(m);
00151 if(delay > 0)
00152 {
00153 Scheduler::instance().schedule(this, m, delay);
00154 }
00155 else
00156 {
00157 nodeCorePtr_->crLayCommand(m);
00158 }
00159 }
00160
00161 void ClSAP::sendSynchronousClLayer(ClMessage* m)
00162 {
00163
00164
00165 if (nodeCorePtr_==0)
00166 {
00167 fprintf(stderr, "Error, ClSAP.sendClModule: nodeCorePtr not yet installed\n");
00168 exit(1);
00169 }
00170 m->direction(TONODECORE);
00171 if (depthNC_ >= m->verbosity())
00172 traceSync(m);
00173 nodeCorePtr_->synchronousCrLayCommand(m);
00174 m->direction(TOMODULE);
00175 if (depthP_ >= m->verbosity())
00176 traceSync(m);
00177 }
00178
00179 int ClSAP::getPluginId()
00180 {
00181 return pluginPtr_?pluginPtr_->getId():NO_MODULE;
00182 }
00183
00184 void ClSAP::handle(Event *e)
00185 {
00186 ClMessage *m = (ClMessage *)e;
00187 if(m->direction() == TONODECORE)
00188 nodeCorePtr_->crLayCommand(m);
00189 else
00190 {
00191 if (depthP_ >= m->verbosity())
00192 trace(m);
00193 RUN_DEPRECATED_OR_NEW_VIRTUAL_METHOD(pluginPtr_->crLayCommand(m), pluginPtr_->recvAsyncClMsg(m));
00194 }
00195 }
00196
00197 Position* ClSAP::getPosition()
00198 {
00199 return nodeCorePtr_->getPosition();
00200 }
00201
00202