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 #include "plugin.h"
00031 #include "scheduler.h"
00032
00033 #include "deprecated.h"
00034 #include "clmsg-discovery.h"
00035
00036
00037
00038
00039
00040 static class PlugInClass : public TclClass {
00041 public:
00042 PlugInClass() : TclClass("PlugIn") {}
00043 TclObject* create(int, const char*const*) {
00044 return (new PlugIn());
00045 }
00046 } class_plugin;
00047
00048 PlugIn::PlugIn() : clsap_(0), binPtr_(0), uLayerId_(0)
00049 {
00050 sprintf(tag_, "---");
00051 }
00052
00053 PlugIn::~PlugIn()
00054 {
00055 }
00056
00057
00058 int PlugIn::command(int argc, const char*const* argv)
00059 {
00060
00061 Tcl& tcl = Tcl::instance();
00062 if (argc==2)
00063 {
00064 if (strcasecmp(argv[1],"Id_")==0)
00065 {
00066 tcl.resultf("%d", getId());
00067 return (TCL_OK);
00068 }
00069 else if (strcasecmp(argv[1],"gettag")==0)
00070 {
00071 tcl.resultf("%s",tag_);
00072 return TCL_OK;
00073 }
00074 }
00075 if (argc==3)
00076 {
00077 if (strcasecmp(argv[1],"Id_")==0)
00078 {
00079 int val = atoi(argv[2]);
00080 setId(val);
00081 return (TCL_OK);
00082 }
00083 if (strcasecmp(argv[1],"addclsap")==0)
00084 {
00085 ClSAP *clsap = dynamic_cast<ClSAP*>(TclObject::lookup(argv[2]));
00086 if (clsap_!=0)
00087 {
00088 tcl.resultf("Error PlugIn::command = %s: a crLay is already installed", argv[1]);
00089 return (TCL_ERROR);
00090 }
00091 clsap_ = clsap;
00092 return (TCL_OK);
00093 }
00094 if (strcasecmp(argv[1],"addbin")==0)
00095 {
00096 Bin *bin = dynamic_cast<Bin*>(TclObject::lookup(argv[2]));
00097 if (binPtr_!=0)
00098 {
00099 tcl.resultf("Error PlugIn::command = %s: a bin is already installed", argv[1]);
00100 return (TCL_ERROR);
00101 }
00102 binPtr_ = bin;
00103 return (TCL_OK);
00104 }
00105
00106 if (strcasecmp(argv[1],"settag")==0)
00107 {
00108 if (strlen(argv[2])>MAX_TAG_LENGTH)
00109 {
00110 tcl.resultf("Error PlugIn::command cmd = %s: plugin tag too long", argv[1]);
00111 return (TCL_ERROR);
00112 }
00113 strcpy(tag_, argv[2]);
00114 return TCL_OK;
00115 }
00116 }
00117 return NsObject::command(argc, argv);
00118 }
00119
00120
00121 int PlugIn::getId()
00122 {
00123 return(uid_);
00124 }
00125
00126 void PlugIn::setId(int val)
00127 {
00128 uid_ = val;
00129 }
00130
00131
00132
00133
00134 int PlugIn::getTag(char* buf, int size)
00135 {
00136 if ((buf==0)||(size<=0)||(tag_==0))
00137 {
00138 return (-1);
00139 }
00140
00141 strncpy(buf, tag_, size);
00142 if (buf[size-1] != '\0')
00143 {
00144 buf[size-1] = '\0';
00145 return 0;
00146 }
00147 else
00148 return 1;
00149
00150 }
00151
00152
00153 int PlugIn::recvAsyncClMsg(ClMessage* m)
00154 {
00155
00156
00157
00158
00159
00160 return RETVAL_NOT_IMPLEMENTED;
00161 }
00162
00163
00164
00165
00166
00167
00168 int PlugIn::crLayCommand(ClMessage* m)
00169 {
00170 delete m;
00171 return RETVAL_NOT_IMPLEMENTED;
00172 }
00173
00174 int PlugIn::getLayer()
00175 {
00176 return(uLayerId_);
00177 }
00178
00179 void PlugIn::setLayer(int val)
00180 {
00181 uLayerId_ = val;
00182 }
00183
00184
00185
00186 int PlugIn::recvSyncClMsg(ClMessage* m)
00187 {
00188 if (m->type() == CLMSG_DISCOVERY) {
00189 Tcl& tcl = Tcl::instance();
00190 tcl.evalf("%s info class", name() );
00191 const char* class_name = tcl.result();
00192 (dynamic_cast<ClMsgDiscovery*>(m))->addData((const PlugIn*)this, getLayer(), getId(), class_name , getTag() );
00193 return 0;
00194 }
00195 else return RETVAL_NOT_IMPLEMENTED;
00196 }
00197
00198
00199 int PlugIn::crLaySynchronousCommand(ClMessage* m)
00200 {
00201 return RETVAL_NOT_IMPLEMENTED;
00202 }
00203
00204
00205
00206 void PlugIn::sendCl(ClMessage* m, double delay)
00207 {
00208 PRINT_WARNING_DEPRECATED_FUNCTION;
00209 sendAsyncClMsg(m, delay);
00210 }
00211
00212 void PlugIn::sendAsyncClMsg(ClMessage* m, double delay)
00213 {
00214 if (clsap_==0)
00215 {
00216 fprintf(stderr, "Error, PlugIn.sendCl: crLayBus_ is not yet installed\n");
00217 exit(1);
00218 }
00219 m->setSource(getId());
00220 clsap_->sendClLayer(m, delay);
00221 }
00222
00223
00224 void PlugIn::sendSynchronousCl(ClMessage* m)
00225 {
00226 PRINT_WARNING_DEPRECATED_FUNCTION;
00227 sendSyncClMsg(m);
00228 }
00229
00230 void PlugIn::sendSyncClMsg(ClMessage* m)
00231 {
00232 if (clsap_==0)
00233 {
00234 fprintf(stderr, "Error, PlugIn.sendCl: crLayBus_ is not yet installed\n");
00235 exit(1);
00236 }
00237 m->setSource(getId());
00238 clsap_->sendSynchronousClLayer(m);
00239 }
00240
00241
00242 void PlugIn::drop(ClMessage* m, const char* reason)
00243 {
00244 binPtr_->drop(m, reason);
00245 }
00246
00247
00248 void PlugIn::recv(Packet* p, Handler* callback)
00249 {
00250
00251
00252 }
00253
00254 Position* PlugIn::getPosition()
00255 {
00256 return clsap_->getPosition();
00257 }
00258