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 #include "Specs.h"
00026
00027
00028
00029 namespace cmlabs {
00030
00031
00032
00033
00034
00035 TriggerSpec::TriggerSpec() {
00036 delayMS = 0;
00037 }
00038
00039 TriggerSpec::TriggerSpec(const JString& xml, JString globalFrom) {
00040 delayMS = 0;
00041 fromXML(xml);
00042 if (globalFrom.length())
00043 from = globalFrom;
00044 }
00045
00046 TriggerSpec::TriggerSpec(XMLNode* node, JString globalFrom) {
00047 delayMS = 0;
00048 fromXML(node);
00049 if (globalFrom.length())
00050 from = globalFrom;
00051 }
00052
00053 TriggerSpec::~TriggerSpec() {
00054 }
00055
00056 Object* TriggerSpec::clone() const {
00057 TriggerSpec* spec = new TriggerSpec();
00058 *spec = *this;
00059 return spec;
00060 }
00061
00062
00063 unsigned long TriggerSpec::getPayloadSize() const {
00064 return alias.getPayloadSize() + from.getPayloadSize() + type.getPayloadSize();
00065 }
00066
00067 bool TriggerSpec::fromXML(const JString& xml) {
00068
00069 if (xml.length() == 0)
00070 return false;
00071
00072 XMLParser* xmlParser = new XMLParser();
00073 xmlParser->parse(xml);
00074 bool ret = fromXML(xmlParser->getRootNode());
00075 delete(xmlParser);
00076 return ret;
00077 }
00078
00079 bool TriggerSpec::fromXML(XMLNode* node) {
00080
00081 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("trigger")) )
00082 return false;
00083
00084 from = node->findAttr("from");
00085 type = node->findAttr("type").toDotString();
00086 if (node->hasAttribute("alias"))
00087 alias = node->findAttr("alias");
00088 else if (node->hasAttribute("name"))
00089 alias = node->findAttr("name");
00090 else
00091 alias = node->findAttr("type");
00092 delayMS = node->findAttr("after").toInt();
00093 return true;
00094 }
00095
00096 JString TriggerSpec::toXML() {
00097 if (alias.equals(type.toText()))
00098 return JString::format("<trigger after=\"%d\" from=\"%s\" type=\"%s\" />", delayMS, (char*) from.xmlStringEncode(), (char*) type.toText().xmlStringEncode());
00099 else
00100 return JString::format("<trigger alias=\"%s\" after=\"%d\" from=\"%s\" type=\"%s\" />", (char*) alias.xmlStringEncode(), delayMS, (char*) from.xmlStringEncode(), (char*) type.toText().xmlStringEncode());
00101 }
00102
00103 JString TriggerSpec::toHTML() {
00104 return print();
00105 }
00106
00107 JString TriggerSpec::print() {
00108
00109 return JString::format("%s after %d ms from %s\n", (char*) type.toText(), delayMS, (char*) from);
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 RetrieveSpec::RetrieveSpec() {
00129 afterTime.setInvalid();
00130 untilTime.setInvalid();
00131 maxCount = minCount = latest = lastMS = -1;
00132 }
00133
00134 RetrieveSpec::RetrieveSpec(const JString& xml, JString globalFrom) {
00135 afterTime.setInvalid();
00136 untilTime.setInvalid();
00137 maxCount = minCount = latest = lastMS = -1;
00138 fromXML(xml);
00139 if (globalFrom.length())
00140 from = globalFrom;
00141 }
00142
00143 RetrieveSpec::RetrieveSpec(XMLNode* node, JString globalFrom) {
00144 afterTime.setInvalid();
00145 untilTime.setInvalid();
00146 maxCount = minCount = latest = lastMS = -1;
00147 fromXML(node);
00148 if (globalFrom.length())
00149 from = globalFrom;
00150 }
00151
00152 RetrieveSpec::~RetrieveSpec() {
00153 }
00154
00155 Object* RetrieveSpec::clone() const {
00156 RetrieveSpec* spec = new RetrieveSpec();
00157 *spec = *this;
00158 return spec;
00159 }
00160
00161
00162 unsigned long RetrieveSpec::getPayloadSize() const {
00163 return from.getPayloadSize() + sender.getPayloadSize() + id.getPayloadSize() +
00164 type.getPayloadSize() + content.getPayloadSize() + contentmatch.getPayloadSize() +
00165 beforeContext.getPayloadSize() + duringContext.getPayloadSize() + afterContext.getPayloadSize() +
00166 afterTime.getPayloadSize() + untilTime.getPayloadSize();
00167 }
00168
00169 ObjectCollection* RetrieveSpec::fromRetrievesXML(const JString& xml) {
00170 if (xml.length() == 0)
00171 return false;
00172
00173 XMLParser* xmlParser = new XMLParser();
00174 xmlParser->parse(xml);
00175 ObjectCollection* ret = fromRetrievesXML(xmlParser->getRootNode());
00176 delete(xmlParser);
00177 return ret;
00178 }
00179
00180 ObjectCollection* RetrieveSpec::fromRetrievesXML(XMLNode* node) {
00181 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("retrieves")) )
00182 return NULL;
00183
00184 ObjectCollection* specs = new ObjectCollection();
00185 ObjectCollection* children = node->getChildTags();
00186 XMLNode* xmlNode;
00187 if (children != NULL) {
00188 for (int n=0; n<children->getCount(); n++) {
00189 xmlNode = (XMLNode*) children->get(n);
00190 if (xmlNode != NULL) {
00191 if (xmlNode->getTag().equalsIgnoreCase("retrieve")) {
00192 specs->add(new RetrieveSpec(xmlNode, node->getAttribute("from")));
00193 }
00194 }
00195 }
00196 }
00197
00198 return specs;
00199 }
00200
00201 bool RetrieveSpec::fromXML(const JString& xml) {
00202
00203 if (xml.length() == 0)
00204 return false;
00205
00206 XMLParser* xmlParser = new XMLParser();
00207 xmlParser->parse(xml);
00208 bool ret = fromXML(xmlParser->getRootNode());
00209 delete(xmlParser);
00210 return ret;
00211 }
00212
00213 bool RetrieveSpec::fromXML(XMLNode* node) {
00214
00215 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("retrieve")) )
00216 return false;
00217
00218 afterTime.setInvalid();
00219 untilTime.setInvalid();
00220
00221 from = node->findAttr("from");
00222 sender = node->findAttr("sender");
00223 id = node->findAttr("id");
00224 type = node->findAttr("type").toDotString();
00225
00226 content = node->findAttr("content");
00227 if (node->hasAttribute("contentraw")) {
00228 content = node->findAttr("contentraw");
00229 contentmatch = "xml";
00230 }
00231 else if (node->hasAttribute("contentmatch")) {
00232 contentmatch = node->findAttr("contentmatch");
00233 }
00234
00235 beforeContext = node->findAttr("beforecontext");
00236 duringContext = node->findAttr("duringcontext");
00237 afterContext = node->findAttr("aftercontext");
00238
00239 bool didSpecifyQuantity = false;
00240
00241 if (node->hasAttribute("latest")) {
00242 latest = node->getAttribute("latest").toInt();
00243 didSpecifyQuantity = true;
00244 }
00245 if (node->hasAttribute("lastmsec")) {
00246 lastMS = node->getAttribute("lastmsec").toInt();
00247 didSpecifyQuantity = true;
00248 }
00249
00250 ObjectCollection* children = node->getChildTags();
00251 XMLNode* xmlNode;
00252 if (children != NULL) {
00253 for (int n=0; n<children->getCount(); n++) {
00254 xmlNode = (XMLNode*) children->get(n);
00255 if (xmlNode != NULL) {
00256 if (xmlNode->getTag().equalsIgnoreCase("latest")) {
00257 latest = xmlNode->getTextContent().toInt();
00258 didSpecifyQuantity = true;
00259 }
00260 else if (xmlNode->getTag().equalsIgnoreCase("afterTime")) {
00261 afterTime = xmlNode->getTextContent().toTime();
00262 didSpecifyQuantity = true;
00263 }
00264 else if (xmlNode->getTag().equalsIgnoreCase("untilTime")) {
00265 untilTime = xmlNode->getTextContent().toTime();
00266 didSpecifyQuantity = true;
00267 }
00268 else if (xmlNode->getTag().equalsIgnoreCase("lastmsec")) {
00269 lastMS = xmlNode->getTextContent().toInt();
00270 didSpecifyQuantity = true;
00271 }
00272 else if (xmlNode->getTag().equalsIgnoreCase("beforecontext")) {
00273 beforeContext = xmlNode->getTextContent().toDotString();
00274 }
00275 else if (xmlNode->getTag().equalsIgnoreCase("duringcontext")) {
00276 duringContext = xmlNode->getTextContent().toDotString();
00277 }
00278 else if (xmlNode->getTag().equalsIgnoreCase("aftercontext")) {
00279 afterContext = xmlNode->getTextContent().toDotString();
00280 }
00281 }
00282 }
00283 }
00284
00285 if (!didSpecifyQuantity) {
00286 latest = 1;
00287 }
00288
00289 return true;
00290 }
00291
00292 JString RetrieveSpec::toXML() {
00293 JString xml;
00294
00295 if (latest > 0)
00296 xml += JString::format("<latest>%d</latest>\n", latest);
00297 if (afterTime.isValid())
00298 xml += JString::format("<afterTime>%d</afterTime>\n", (char*) afterTime.asText());
00299 if (untilTime.isValid())
00300 xml += JString::format("<untilTime>%d</untilTime>\n", (char*) untilTime.asText());
00301 if (lastMS > 0)
00302 xml += JString::format("<lastmsec>%d</lastmsec>\n", lastMS);
00303
00304 if (beforeContext.getCount() > 0)
00305 xml += JString::format("<beforecontext>%s</beforecontext>\n", (char*) beforeContext.toText().xmlStringEncode());
00306 if (duringContext.getCount() > 0)
00307 xml += JString::format("<duringcontext>%s</duringcontext>\n", (char*) duringContext.toText().xmlStringEncode());
00308 if (afterContext.getCount() > 0)
00309 xml += JString::format("<aftercontext>%s</aftercontext>\n", (char*) afterContext.toText().xmlStringEncode());
00310
00311 if (xml.length() > 0)
00312 return JString::format("<retrieve from=\"%s\" sender=\"%s\" type=\"%s\" id=\"%s\" content=\"%s\" contentmatch=\"%s\">\n%s</retrieve>",
00313 (char*) from.xmlStringEncode(), (char*) sender.xmlStringEncode(), (char*) type.toText().xmlStringEncode(), (char*) id.xmlStringEncode(), (char*) content.xmlStringEncode(), (char*) contentmatch.xmlStringEncode(), (char*) xml.indentXML());
00314 else
00315 return JString::format("<retrieve from=\"%s\" sender=\"%s\" type=\"%s\" id=\"%s\" content=\"%s\" contentmatch=\"%s\" />",
00316 (char*) from.xmlStringEncode(), (char*) sender.xmlStringEncode(), (char*) type.toText().xmlStringEncode(), (char*) id.xmlStringEncode(), (char*) content.xmlStringEncode(), (char*) contentmatch.xmlStringEncode());
00317 }
00318
00319 JString RetrieveSpec::toHTML() {
00320 return print();
00321 }
00322
00323 JString RetrieveSpec::print() {
00324
00325 return JString::format("%s from %s\n", (char*) type.toText(), (char*) from);
00326 }
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 CrankSpec::CrankSpec() {
00347 continuous = false;
00348
00349 }
00350
00351 CrankSpec::CrankSpec(const JString& xml) {
00352 continuous = false;
00353
00354 fromXML(xml);
00355 }
00356
00357 CrankSpec::CrankSpec(XMLNode* node) {
00358 continuous = false;
00359
00360 fromXML(node);
00361 }
00362
00363 CrankSpec::~CrankSpec() {
00364
00365 }
00366
00367 Object* CrankSpec::clone() const {
00368 CrankSpec* spec = new CrankSpec();
00369 spec->name = this->name;
00370 spec->continuous = continuous;
00371
00372 return spec;
00373 }
00374
00375
00376 unsigned long CrankSpec::getPayloadSize() const {
00377 return name.getPayloadSize();
00378 }
00379
00380 bool CrankSpec::fromXML(const JString& xml) {
00381
00382 if (xml.length() == 0)
00383 return false;
00384
00385 XMLParser* xmlParser = new XMLParser();
00386 xmlParser->parse(xml);
00387 bool ret = fromXML(xmlParser->getRootNode());
00388 delete(xmlParser);
00389 return ret;
00390 }
00391
00392 bool CrankSpec::fromXML(XMLNode* node) {
00393
00394 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("crank")) )
00395 return false;
00396
00397 name = node->findAttr("name");
00398
00399 if (node->getAttribute("type").startsWithIgnoreCase("cont")) {
00400 continuous = true;
00401 }
00402 else
00403 continuous = false;
00404
00405 ObjectCollection* children = node->getChildTags();
00406 if ( (children == NULL) || (children->getCount() == 0))
00407 return true;
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436 return true;
00437 }
00438
00439 JString CrankSpec::toXML() {
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453 JString type;
00454 if (continuous)
00455 type = "type=\"continuous\"";
00456
00457
00458
00459
00460
00461 return JString::format("<crank name=\"%s\" %s />", (char*) name.xmlStringEncode(), (char*) type.xmlStringEncode());
00462 }
00463
00464 JString CrankSpec::toHTML() {
00465 return print();
00466 }
00467
00468 JString CrankSpec::print() {
00469 return JString::format("Crank '%s'\n", (char*) name);
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 PostSpec::PostSpec() {
00496 priority = 1;
00497 useInReplyTo = true;
00498 noreply = false;
00499 object = NULL;
00500 }
00501
00502 PostSpec::PostSpec(const JString& xml, JString globalTo) {
00503 priority = 1;
00504 useInReplyTo = true;
00505 noreply = false;
00506 object = NULL;
00507 fromXML(xml);
00508 if (globalTo.length())
00509 to = globalTo;
00510 }
00511
00512 PostSpec::PostSpec(XMLNode* node, JString globalTo) {
00513 priority = 1;
00514 useInReplyTo = true;
00515 noreply = false;
00516 object = NULL;
00517 fromXML(node);
00518 if (globalTo.length())
00519 to = globalTo;
00520 }
00521
00522 PostSpec::~PostSpec() {
00523 if (object != NULL)
00524 delete(object);
00525 object = NULL;
00526 }
00527
00528 Object* PostSpec::clone() const {
00529 PostSpec* spec = new PostSpec();
00530 *spec = *this;
00531 if (object != NULL)
00532 spec->object = object->clone();
00533 return spec;
00534 }
00535
00536
00537 unsigned long PostSpec::getPayloadSize() const {
00538 unsigned long payloadSize = from.getPayloadSize() + alias.getPayloadSize() + to.getPayloadSize() +
00539 cc.getPayloadSize() + phasechange.getPayloadSize() + type.getPayloadSize() +
00540 content.getPayloadSize() + language.getPayloadSize();
00541 if (object != NULL) payloadSize += object->getPayloadSize();
00542 return payloadSize;
00543 }
00544
00545 bool PostSpec::fromXML(const JString& xml) {
00546
00547 if (xml.length() == 0)
00548 return false;
00549
00550 XMLParser* xmlParser = new XMLParser();
00551 xmlParser->parse(xml);
00552 bool ret = fromXML(xmlParser->getRootNode());
00553 delete(xmlParser);
00554 return ret;
00555 }
00556
00557 bool PostSpec::fromXML(XMLNode* node) {
00558
00559 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("post")) )
00560 return false;
00561
00562 from = node->findAttr("from");
00563 to = node->findAttr("to");
00564 cc = node->findAttr("cc");
00565 type = node->findAttr("type").toDotString();
00566 language = node->findAttr("language");
00567 phasechange = node->findAttr("phasechange");
00568 if (node->hasAttribute("content"))
00569 content = node->getAttribute("content");
00570 else {
00571 if (language.equalsIgnoreCase("xml")) {
00572 object = Object::createObjectFromXML(node->getTextContent());
00573 }
00574 else {
00575 content = node->getTextContent();
00576 }
00577 }
00578 if (node->hasAttribute("alias"))
00579 alias = node->findAttr("alias");
00580 else if (node->hasAttribute("name"))
00581 alias = node->findAttr("name");
00582 else
00583 alias = node->findAttr("type");
00584
00585 if (node->hasAttribute("priority"))
00586 priority = node->getAttribute("priority").toDouble();
00587
00588 if (node->getAttribute("useinreplyto").equalsIgnoreCase("no")) {
00589 useInReplyTo = false;
00590 }
00591
00592 if (node->getAttribute("noreply").length() > 0) {
00593 noreply = true;
00594 }
00595
00596 return true;
00597 }
00598
00599 JString PostSpec::toXML() {
00600
00601 JString xml;
00602 if (object != NULL) {
00603 xml = object->toXML();
00604 language = "xml";
00605 }
00606 else if (content.contains("\n"))
00607 xml = content;
00608
00609 JString inreplytext;
00610 if (!useInReplyTo)
00611 inreplytext = " useinreplyto=\"no\"";
00612 if (noreply)
00613 inreplytext += " noreply=\"yes\"";
00614
00615 JString nameparm;
00616 if (!nameparm.equals(type.toText()))
00617 nameparm = JString::format("alias=\"%s\" ", (char*) alias.xmlStringEncode());
00618
00619 if (xml.length() > 0) {
00620 return JString::format("<post %sfrom=\"%s\" to=\"%s\" cc=\"%s\" type=\"%s\" phasechange=\"%s\" language=\"%s\" priority=\"%f\" %s>\n%s</post>",
00621 (char*) nameparm, (char*) from.xmlStringEncode(), (char*) to.xmlStringEncode(), (char*) cc.xmlStringEncode(), (char*) type.toText().xmlStringEncode(), (char*) phasechange.xmlStringEncode(),
00622 (char*) language.xmlStringEncode(), priority, (char*) inreplytext, (char*) xml.indentXML());
00623 }
00624 else
00625 return JString::format("<post %sfrom=\"%s\" to=\"%s\" cc=\"%s\" type=\"%s\" phasechange=\"%s\" language=\"%s\" priority=\"%f\" content=\"%s\" %s />",
00626 (char*) nameparm, (char*) from.xmlStringEncode(), (char*) to.xmlStringEncode(), (char*) cc.xmlStringEncode(), (char*) type.toText().xmlStringEncode(), (char*) phasechange.xmlStringEncode(),
00627 (char*) language.xmlStringEncode(), priority, (char*) content.xmlStringEncode(), (char*) inreplytext);
00628 }
00629
00630 JString PostSpec::toHTML() {
00631 return print();
00632 }
00633
00634 JString PostSpec::print() {
00635
00636 JString extra;
00637 if (cc.length() > 0)
00638 extra = JString::format(" (cc: %s)", (char*) cc);
00639 if (phasechange.equalsIgnoreCase("yes"))
00640 extra = JString::format("%s [phasechange]", (char*) extra);
00641 return JString::format("%s to %s%s\n", (char*) type.toText(), (char*) to, (char*) extra);
00642 }
00643
00644
00645
00646
00647
00648
00649
00650 long PostSpec::getBinarySize(int chunk) {
00651 if (object == NULL)
00652 return 0;
00653 return object->getBinarySize(chunk);
00654 }
00655
00656
00657 int PostSpec::getBinaryChunkCount() {
00658 if (object == NULL)
00659 return 0;
00660 return object->getBinaryChunkCount();
00661 }
00662
00663
00664 long PostSpec::toBinaryBuffer(int chunk, char* buffer, int maxlen) {
00665 if (object == NULL)
00666 return false;
00667 return object->toBinaryBuffer(chunk, buffer, maxlen);
00668 }
00669
00670
00671 bool PostSpec::fromBinaryBuffer(int chunk, char* buffer, long len) {
00672 if (object == NULL)
00673 return false;
00674 return object->fromBinaryBuffer(chunk, buffer, len);
00675 }
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 PhaseSpec::PhaseSpec() {
00695 triggers = new ObjectCollection();
00696
00697 retrieves = new ObjectCollection();
00698 cranks = new ObjectCollection();
00699 posts = new ObjectCollection();
00700 streams = new ObjectCollection();
00701 currentContexts = NULL;
00702 allowSelfTriggering = false;
00703 name = "";
00704 moduleName = "";
00705 context = "";
00706 priority = 1;
00707 activationTime.setInvalid();
00708 pid = createUniqueID();
00709 }
00710
00711 PhaseSpec::PhaseSpec(const JString& xml) {
00712 triggers = new ObjectCollection();
00713
00714 retrieves = new ObjectCollection();
00715 cranks = new ObjectCollection();
00716 posts = new ObjectCollection();
00717 streams = new ObjectCollection();
00718 currentContexts = NULL;
00719 name = "";
00720 moduleName = "";
00721 context = "";
00722 allowSelfTriggering = false;
00723 priority = 1;
00724 activationTime.setInvalid();
00725 pid = createUniqueID();
00726 fromXML(xml);
00727 }
00728
00729 PhaseSpec::PhaseSpec(XMLNode* node) {
00730 triggers = new ObjectCollection();
00731
00732 retrieves = new ObjectCollection();
00733 cranks = new ObjectCollection();
00734 posts = new ObjectCollection();
00735 streams = new ObjectCollection();
00736 currentContexts = NULL;
00737 name = "";
00738 moduleName = "";
00739 context = "";
00740 allowSelfTriggering = false;
00741 priority = 1;
00742 activationTime.setInvalid();
00743 pid = createUniqueID();
00744 fromXML(node);
00745 }
00746
00747 PhaseSpec::~PhaseSpec() {
00748 delete(triggers);
00749
00750 delete(retrieves);
00751 delete(cranks);
00752 delete(posts);
00753 delete(streams);
00754 delete(currentContexts);
00755
00756 }
00757
00758 Object* PhaseSpec::clone() const {
00759 PhaseSpec* spec = new PhaseSpec();
00760 spec->priority = priority;
00761 spec->name = this->name;
00762 spec->moduleName = this->moduleName;
00763 spec->context = this->context;
00764 spec->allowSelfTriggering = this->allowSelfTriggering;
00765 spec->triggers->copyAll(triggers);
00766
00767 spec->retrieves->copyAll(retrieves);
00768 spec->cranks->copyAll(cranks);
00769 spec->posts->copyAll(posts);
00770 spec->streams->copyAll(streams);
00771 spec->activationTime = activationTime;
00772 if (currentContexts != NULL)
00773 spec->currentContexts = (ObjectDictionary*) currentContexts->clone();
00774 spec->pid = pid;
00775 return spec;
00776 }
00777
00778
00779 unsigned long PhaseSpec::getPayloadSize() const {
00780 unsigned long payloadSize = activationTime.getPayloadSize() + name.getPayloadSize() + pid.getPayloadSize() +
00781 moduleName.getPayloadSize() + context.getPayloadSize() + lastTriggerName.getPayloadSize();
00782
00783 if (currentContexts != NULL) payloadSize += currentContexts->getPayloadSize();
00784 if (triggers != NULL) payloadSize += triggers->getPayloadSize();
00785 if (retrieves != NULL) payloadSize += retrieves->getPayloadSize();
00786 if (cranks != NULL) payloadSize += cranks->getPayloadSize();
00787 if (posts != NULL) payloadSize += posts->getPayloadSize();
00788 if (streams != NULL) payloadSize += streams->getPayloadSize();
00789
00790 return payloadSize;
00791 }
00792
00793 bool PhaseSpec::equals(const Object *o2) {
00794 if (!this->isSameClass(o2))
00795 return false;
00796 return ( ((PhaseSpec*)o2)->pid.equalsIgnoreCase(pid) );
00797
00798 }
00799
00800 int PhaseSpec::compare(const Object *o2) {
00801 if (!this->isSameClass(o2))
00802 return false;
00803 if (!((PhaseSpec*)o2)->activationTime.isValid())
00804 return 1;
00805 else if (!activationTime.isValid())
00806 return -1;
00807 else
00808 return activationTime.compare(&((PhaseSpec*)o2)->activationTime);
00809 }
00810
00811 bool PhaseSpec::isNewerThan(const PhaseSpec* spec) {
00812 if (!spec->activationTime.isValid())
00813 return true;
00814 else if (!activationTime.isValid())
00815 return false;
00816 else
00817 return (activationTime > spec->activationTime);
00818 }
00819
00820 bool PhaseSpec::isOlderThan(const PhaseSpec* spec) {
00821 if (!activationTime.isValid())
00822 return true;
00823 else if (!spec->activationTime.isValid())
00824 return false;
00825 else
00826 return (activationTime < spec->activationTime);
00827 }
00828
00829
00830 bool PhaseSpec::containsGlobalTrigger() {
00831
00832 TriggerSpec* trigger;
00833 for (int n=0; n<triggers->getCount(); n++) {
00834 if ( (trigger = (TriggerSpec*) triggers->get(n)) != NULL ) {
00835 if ( (trigger->from.equalsIgnoreCase("any")) || (trigger->from.equalsIgnoreCase("*")) || (trigger->from.length() == 0) )
00836 return true;
00837 }
00838 }
00839 return false;
00840 }
00841
00842
00843 bool PhaseSpec::fromXML(const JString& xml) {
00844
00845 if (xml.length() == 0)
00846 return false;
00847
00848 XMLParser* xmlParser = new XMLParser();
00849 xmlParser->parse(xml);
00850 bool ret = fromXML(xmlParser->getRootNode());
00851 delete(xmlParser);
00852 return ret;
00853 }
00854
00855 bool PhaseSpec::fromXML(XMLNode* node) {
00856
00857 if (node == NULL)
00858 return false;
00859
00860 triggers->removeAll();
00861
00862 retrieves->removeAll();
00863 cranks->removeAll();
00864 posts->removeAll();
00865
00866 XMLNode* xmlNode;
00867 if (node->getTag().equalsIgnoreCase("phase")) {
00868 if (node->hasAttribute("priority"))
00869 priority = node->findAttr("priority").toDouble();
00870 if (node->hasAttribute("id"))
00871 name = node->findAttr("id");
00872 else
00873 name = node->findAttr("name");
00874 if (node->hasAttribute("pid")) {
00875 if (node->getAttribute("pid").length() > 0)
00876 pid = node->getAttribute("pid");
00877 }
00878 JString str = node->findAttr("module");
00879 if (str.length() > 0)
00880 moduleName = str;
00881 str = node->findAttr("context");
00882 if (str.length() > 0)
00883 context = str;
00884 xmlNode = node->getChildNode("allowselftriggering");
00885 if ((xmlNode != NULL) && (xmlNode->getTextContent().equalsIgnoreCase("yes"))) {
00886 allowSelfTriggering = true;
00887 }
00888 else if ((xmlNode != NULL) && (xmlNode->getTextContent().equalsIgnoreCase("no"))) {
00889 allowSelfTriggering = false;
00890 }
00891 lastTriggerName = node->findAttr("lasttrigger");
00892 }
00893
00894 ObjectCollection* children = node->getChildTags();
00895 if ( (children == NULL) || (children->getCount() == 0))
00896 return true;
00897
00898 XMLNode* subNode, *streamNode;
00899 ObjectCollection* subNodes;
00900 ObjectCollection *streamNodes;
00901 TriggerSpec* triggerSpec;
00902 PostSpec* postSpec;
00903
00904 for (int n=0; n<children->getCount(); n++) {
00905 xmlNode = (XMLNode*) children->get(n);
00906 if (xmlNode != NULL) {
00907 if (xmlNode->getTag().equalsIgnoreCase("triggers")) {
00908 if ( (subNodes = xmlNode->getChildTags()) != NULL) {
00909 for (int m=0; m<subNodes->getCount(); m++) {
00910 subNode = (XMLNode*) subNodes->get(m);
00911 if ( (subNode != NULL) && (subNode->getTag().equalsIgnoreCase("trigger")) ) {
00912 triggerSpec = new TriggerSpec(subNode, xmlNode->findAttr("from"));
00913
00914
00915 triggers->add(triggerSpec);
00916 }
00917 }
00918 }
00919 }
00920 else if (xmlNode->getTag().equalsIgnoreCase("retrieves")) {
00921 if ( (subNodes = xmlNode->getChildTags()) != NULL) {
00922 for (int m=0; m<subNodes->getCount(); m++) {
00923 subNode = (XMLNode*) subNodes->get(m);
00924 if ( (subNode != NULL) && (subNode->getTag().equalsIgnoreCase("retrieve")) ) {
00925 retrieves->add(new RetrieveSpec(subNode, xmlNode->findAttr("from")));
00926 }
00927 }
00928 }
00929 }
00930 else if (xmlNode->getTag().equalsIgnoreCase("cranks")) {
00931 if ( (subNodes = xmlNode->getChildTags()) != NULL) {
00932 for (int m=0; m<subNodes->getCount(); m++) {
00933 subNode = (XMLNode*) subNodes->get(m);
00934 if ( (subNode != NULL) && (subNode->getTag().equalsIgnoreCase("crank")) ) {
00935 cranks->add(new CrankSpec(subNode));
00936 if ( (streamNodes = subNode->getChildTags()) != NULL) {
00937 for (int mm=0; mm<streamNodes->getCount(); mm++) {
00938 streamNode = (XMLNode*) streamNodes->get(mm);
00939 if ( (streamNode != NULL) && (streamNode->getTag().containsIgnoreCase("stream")) ) {
00940 streams->add(new StreamAccess(streamNode));
00941 }
00942 }
00943 }
00944 }
00945 }
00946 }
00947 }
00948 else if (xmlNode->getTag().equalsIgnoreCase("posts")) {
00949 if ( (subNodes = xmlNode->getChildTags()) != NULL) {
00950 for (int m=0; m<subNodes->getCount(); m++) {
00951 subNode = (XMLNode*) subNodes->get(m);
00952 if ( (subNode != NULL) && (subNode->getTag().equalsIgnoreCase("post")) ) {
00953 postSpec = new PostSpec(subNode, xmlNode->findAttr("to"));
00954 if (!subNode->hasAttribute("priority"))
00955 postSpec->priority = priority;
00956 posts->add(postSpec);
00957 }
00958 }
00959 }
00960 }
00961 else if (xmlNode->getTag().equalsIgnoreCase("streams")) {
00962 if ( (subNodes = xmlNode->getChildTags()) != NULL) {
00963 for (int m=0; m<subNodes->getCount(); m++) {
00964 subNode = (XMLNode*) subNodes->get(m);
00965 if ( (subNode != NULL) && (subNode->getTag().containsIgnoreCase("stream")) ) {
00966 streams->add(new StreamAccess(subNode));
00967 }
00968 }
00969 }
00970 }
00971 else if (xmlNode->getTag().equalsIgnoreCase("currentcontexts")) {
00972 currentContexts = new ObjectDictionary();
00973 if (!currentContexts->fromXML(xmlNode->getFirstChildNode())) {
00974 delete(currentContexts);
00975 currentContexts = NULL;
00976 }
00977 }
00978 else if (xmlNode->getTag().equalsIgnoreCase("trigger")) {
00979 triggers->add(new TriggerSpec(xmlNode));
00980 }
00981 else if (xmlNode->getTag().equalsIgnoreCase("retrieve")) {
00982 retrieves->add(new RetrieveSpec(xmlNode));
00983 }
00984 else if (xmlNode->getTag().equalsIgnoreCase("crank")) {
00985 cranks->add(new CrankSpec(xmlNode));
00986 if ( (streamNodes = xmlNode->getChildTags()) != NULL) {
00987 for (int m=0; m<streamNodes->getCount(); m++) {
00988 streamNode = (XMLNode*) streamNodes->get(m);
00989 if ( (streamNode != NULL) && (streamNode->getTag().containsIgnoreCase("stream")) ) {
00990 streams->add(new StreamAccess(streamNode));
00991 }
00992 }
00993 }
00994 }
00995 else if (xmlNode->getTag().equalsIgnoreCase("post")) {
00996 postSpec = new PostSpec(xmlNode);
00997 if (!xmlNode->hasAttribute("priority"))
00998 postSpec->priority = priority;
00999 posts->add(postSpec);
01000 }
01001 else if (xmlNode->getTag().containsIgnoreCase("stream")) {
01002 streams->add(new StreamAccess(xmlNode));
01003 }
01004 else if (xmlNode->getTag().equalsIgnoreCase("activationtime")) {
01005 activationTime = JTime(xmlNode);
01006 }
01007 }
01008 }
01009
01010
01011
01012
01013
01014
01015 return true;
01016 }
01017
01018 JString PhaseSpec::toXML() {
01019 JString xml, subXML;
01020 int n;
01021
01022 if (allowSelfTriggering)
01023 xml += JString::format("<allowselftriggering>Yes</allowselftriggering>\n");
01024
01025 TriggerSpec* triggerSpec;
01026 if (triggers->getCount() > 0) {
01027 subXML = "";
01028
01029
01030
01031
01032
01033 for (n=0; n<triggers->getCount(); n++) {
01034 triggerSpec = (TriggerSpec*) triggers->get(n);
01035 if (triggerSpec != NULL)
01036 subXML += triggerSpec->toXML() + "\n";
01037 }
01038 xml += JString::format("<triggers>\n%s</triggers>\n", (char*) subXML.indentXML());
01039 }
01040
01041 RetrieveSpec* retrieveSpec;
01042 if (retrieves->getCount() > 0) {
01043 subXML = "";
01044 for (n=0; n<retrieves->getCount(); n++) {
01045 retrieveSpec = (RetrieveSpec*) retrieves->get(n);
01046 if (retrieveSpec != NULL)
01047 subXML += retrieveSpec->toXML() + "\n";
01048 }
01049 xml += JString::format("<retrieves>\n%s</retrieves>\n", (char*) subXML.indentXML());
01050 }
01051
01052 CrankSpec* crankSpec;
01053 if (cranks->getCount() > 0) {
01054 subXML = "";
01055 for (n=0; n<cranks->getCount(); n++) {
01056 crankSpec = (CrankSpec*) cranks->get(n);
01057 if (crankSpec != NULL)
01058 subXML += crankSpec->toXML() + "\n";
01059 }
01060 xml += JString::format("<cranks>\n%s</cranks>\n", (char*) subXML.indentXML());
01061 }
01062
01063 PostSpec* postSpec;
01064 if (posts->getCount() > 0) {
01065 subXML = "";
01066 for (n=0; n<posts->getCount(); n++) {
01067 postSpec = (PostSpec*) posts->get(n);
01068 if (postSpec != NULL)
01069 subXML += postSpec->toXML() + "\n";
01070 }
01071 xml += JString::format("<posts>\n%s</posts>\n", (char*) subXML.indentXML());
01072 }
01073
01074 StreamAccess* streamSpec;
01075 if (streams->getCount() > 0) {
01076 subXML = "";
01077 for (n=0; n<streams->getCount(); n++) {
01078 streamSpec = (StreamAccess*) streams->get(n);
01079 if (streamSpec != NULL)
01080 subXML += streamSpec->toXML() + "\n";
01081 }
01082 xml += JString::format("<streams>\n%s</streams>\n", (char*) subXML.indentXML());
01083 }
01084
01085 if (currentContexts != NULL) {
01086 xml += JString::format("<currentcontexts>\n%s</currentcontexts>\n", (char*) currentContexts->toXML().indentXML());
01087 }
01088
01089 xml += activationTime.toXML("activationtime") + "\n";
01090
01091
01092
01093 return JString::format("<phase name=\"%s\" module=\"%s\" context=\"%s\" lasttrigger=\"%s\" pid=\"%s\" priority=\"%.3f\">\n%s</phase>",
01094 (char*) name.xmlStringEncode(), (char*) moduleName.xmlStringEncode(), (char*) context.xmlStringEncode(), (char*) lastTriggerName.xmlStringEncode(), (char*) pid.xmlStringEncode(), priority, (char*) xml.indentXML());
01095 }
01096
01097 JString PhaseSpec::print() {
01098 int n;
01099 JString html = JString::format("Phase %s: [%s] %s\n", (char*) name, (char*) context, (char*) moduleName);
01100
01101 if (triggers->getCount() > 0) {
01102 html += "Triggers:\n";
01103 TriggerSpec* triggerSpec;
01104 for (n=0; n<triggers->getCount(); n++) {
01105 triggerSpec = (TriggerSpec*) triggers->get(n);
01106 if (triggerSpec != NULL) {
01107 html += JString("- ") + triggerSpec->toHTML() + "\n";
01108 }
01109 }
01110 }
01111
01112 if (retrieves->getCount() > 0) {
01113 html += "Retrieves:\n";
01114 RetrieveSpec* retrieveSpec;
01115 for (n=0; n<retrieves->getCount(); n++) {
01116 retrieveSpec = (RetrieveSpec*) retrieves->get(n);
01117 if (retrieveSpec != NULL) {
01118 html += JString("- ") + retrieveSpec->toHTML() + "\n";
01119 }
01120 }
01121 }
01122
01123 if (cranks->getCount() > 0) {
01124 html += "Cranks:\n";
01125 CrankSpec* crankSpec;
01126 for (n=0; n<cranks->getCount(); n++) {
01127 crankSpec = (CrankSpec*) cranks->get(n);
01128 if (crankSpec != NULL) {
01129 html += JString("- ") + crankSpec->toHTML() + "\n";
01130 }
01131 }
01132 }
01133
01134 if (posts->getCount() > 0) {
01135 html += "Posts:\n";
01136 PostSpec* postSpec;
01137 for (n=0; n<posts->getCount(); n++) {
01138 postSpec = (PostSpec*) posts->get(n);
01139 if (postSpec != NULL) {
01140 html += JString("- ") + postSpec->toHTML() + "\n";
01141 }
01142 }
01143 }
01144
01145 if (streams->getCount() > 0) {
01146 html += "Streams:\n";
01147 StreamAccess* streamSpec;
01148 for (n=0; n<streams->getCount(); n++) {
01149 streamSpec = (StreamAccess*) streams->get(n);
01150 if (streamSpec != NULL) {
01151 html += JString("- ") + streamSpec->toHTML() + "\n";
01152 }
01153 }
01154 }
01155
01156 return html;
01157 }
01158
01159 JString PhaseSpec::toHTML() {
01160
01161 int n;
01162 JString html;
01163
01164 if (triggers->getCount() > 0) {
01165 html += "<tr><td class=\"MessageShowDataName\" align=\"right\" valign=\"top\">Triggers</td><td colspan=\"3\" class=\"MessageShowDataValue\">";
01166 TriggerSpec* triggerSpec;
01167 for (n=0; n<triggers->getCount(); n++) {
01168 triggerSpec = (TriggerSpec*) triggers->get(n);
01169 if (triggerSpec != NULL) {
01170 html += triggerSpec->toHTML() + "<br>";
01171 }
01172 }
01173 html += "</td></tr>\n";
01174 }
01175
01176 if (retrieves->getCount() > 0) {
01177 html += "<tr><td class=\"MessageShowDataName\" align=\"right\" valign=\"top\">Retrieves</td><td colspan=\"3\" class=\"MessageShowDataValue\">";
01178 RetrieveSpec* retrieveSpec;
01179 for (n=0; n<retrieves->getCount(); n++) {
01180 retrieveSpec = (RetrieveSpec*) retrieves->get(n);
01181 if (retrieveSpec != NULL) {
01182 html += retrieveSpec->toHTML() + "<br>";
01183 }
01184 }
01185 html += "</td></tr>\n";
01186 }
01187
01188 if (cranks->getCount() > 0) {
01189 html += "<tr><td class=\"MessageShowDataName\" align=\"right\" valign=\"top\">Cranks</td><td colspan=\"3\" class=\"MessageShowDataValue\">";
01190 CrankSpec* crankSpec;
01191 for (n=0; n<cranks->getCount(); n++) {
01192 crankSpec = (CrankSpec*) cranks->get(n);
01193 if (crankSpec != NULL) {
01194 html += crankSpec->toHTML() + "<br>";
01195 }
01196 }
01197 html += "</td></tr>\n";
01198 }
01199
01200 if (posts->getCount() > 0) {
01201 html += "<tr><td class=\"MessageShowDataName\" align=\"right\" valign=\"top\">Posts</td><td colspan=\"3\" class=\"MessageShowDataValue\">";
01202 PostSpec* postSpec;
01203 for (n=0; n<posts->getCount(); n++) {
01204 postSpec = (PostSpec*) posts->get(n);
01205 if (postSpec != NULL) {
01206 html += postSpec->toHTML() + "<br>";
01207 }
01208 }
01209 html += "</td></tr>\n";
01210 }
01211
01212 if (streams->getCount() > 0) {
01213 html += "<tr><td class=\"MessageShowDataName\" align=\"right\" valign=\"top\">Streams</td><td colspan=\"3\" class=\"MessageShowDataValue\">";
01214 StreamAccess* streamSpec;
01215 for (n=0; n<streams->getCount(); n++) {
01216 streamSpec = (StreamAccess*) streams->get(n);
01217 if (streamSpec != NULL) {
01218 html += streamSpec->toHTML() + "<br>";
01219 }
01220 }
01221 html += "</td></tr>\n";
01222 }
01223
01224 return JString::format("<table class=\"MessageShowTable\" width=\"100%%\">\
01225 <tr><td class=\"MessageShowDataName\" align=\"right\">CONTEXT</td><td colspan=\"3\" class=\"MessageShowDataValue\">%s</td></tr>\
01226 <tr><td class=\"MessageShowDataName\" align=\"right\">Phase</td><td colspan=\"3\" class=\"MessageShowDataValue\">%s</td></tr>\
01227 %s</table>",
01228 (char*) context, (char*) name, (char*) html);
01229 }
01230
01231
01232
01233
01234
01235
01236
01237 long PhaseSpec::getBinarySize(int chunk) {
01238 if (posts == NULL)
01239 return 0;
01240 return posts->getBinarySize(chunk);
01241 }
01242
01243
01244 int PhaseSpec::getBinaryChunkCount() {
01245 if (posts == NULL)
01246 return 0;
01247 return posts->getBinaryChunkCount();
01248 }
01249
01250
01251 long PhaseSpec::toBinaryBuffer(int chunk, char* buffer, int maxlen) {
01252 if (posts == NULL)
01253 return false;
01254 return posts->toBinaryBuffer(chunk, buffer, maxlen);
01255 }
01256
01257
01258 bool PhaseSpec::fromBinaryBuffer(int chunk, char* buffer, long len) {
01259 if (posts == NULL)
01260 return false;
01261 return posts->fromBinaryBuffer(chunk, buffer, len);
01262 }
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286 ContextSpec::ContextSpec() {
01287 currentContexts = new ObjectDictionary();
01288 phases = new ObjectCollection();
01289 currentActivePhases = new ObjectCollection();
01290 currentActivePhases->noDelete();
01291 currentPhaseNum = 0;
01292 currentPhase = NULL;
01293 wasActive = false;
01294 allowSelfTriggering = false;
01295 priority = 1;
01296 }
01297
01298 ContextSpec::ContextSpec(const JString& xml) {
01299 currentContexts = new ObjectDictionary();
01300 phases = new ObjectCollection();
01301 currentActivePhases = new ObjectCollection();
01302 currentActivePhases->noDelete();
01303 currentPhaseNum = 0;
01304 currentPhase = NULL;
01305 allowSelfTriggering = false;
01306 priority = 1;
01307 fromXML(xml);
01308 wasActive = false;
01309 }
01310
01311 ContextSpec::ContextSpec(XMLNode* node) {
01312 currentContexts = new ObjectDictionary();
01313 phases = new ObjectCollection();
01314 currentActivePhases = new ObjectCollection();
01315 currentActivePhases->noDelete();
01316 currentPhaseNum = 0;
01317 currentPhase = NULL;
01318 allowSelfTriggering = false;
01319 priority = 1;
01320 fromXML(node);
01321 wasActive = false;
01322 }
01323
01324 ContextSpec::~ContextSpec() {
01325 delete(currentContexts);
01326 delete(currentActivePhases);
01327 delete(phases);
01328 }
01329
01330 Object* ContextSpec::clone() const {
01331 ContextSpec* spec = new ContextSpec();
01332 spec->name = this->name;
01333 spec->moduleName = this->moduleName;
01334 spec->currentPhaseNum = this->currentPhaseNum;
01335 spec->ownContext = this->ownContext;
01336 spec->allowSelfTriggering = this->allowSelfTriggering;
01337 spec->phases->copyAll(phases);
01338
01339 spec->reset();
01340 return spec;
01341 }
01342
01343
01344 unsigned long ContextSpec::getPayloadSize() const {
01345 unsigned long payloadSize = name.getPayloadSize() + moduleName.getPayloadSize() + ownContext.getPayloadSize();
01346
01347 if (currentPhase != NULL) payloadSize += currentPhase->getPayloadSize();
01348 if (currentActivePhases != NULL) payloadSize += currentActivePhases->getPayloadSize();
01349 if (phases != NULL) payloadSize += phases->getPayloadSize();
01350 if (currentContexts != NULL) payloadSize += currentContexts->getPayloadSize();
01351
01352 return payloadSize;
01353 }
01354
01355 bool ContextSpec::fromXML(const JString& xml) {
01356
01357 if (xml.length() == 0)
01358 return false;
01359
01360 XMLParser* xmlParser = new XMLParser();
01361 xmlParser->parse(xml);
01362 bool ret = fromXML(xmlParser->getRootNode());
01363 delete(xmlParser);
01364 return ret;
01365 }
01366
01367 bool ContextSpec::fromXML(XMLNode* node) {
01368
01369 if (node == NULL)
01370 return false;
01371
01372 phases->removeAll();
01373 currentPhaseNum = 0;
01374
01375 XMLNode* xmlNode;
01376 if (node->getTag().equalsIgnoreCase("context")) {
01377 name = node->findAttr("name");
01378 ownContext = name.toDotString();
01379 JString str = node->findAttr("module");
01380 if (str.length() > 0)
01381 moduleName = str;
01382
01383 xmlNode = node->getChildNode("allowselftriggering");
01384 if ((xmlNode != NULL) && (xmlNode->getTextContent().equalsIgnoreCase("yes"))) {
01385 allowSelfTriggering = true;
01386 }
01387 else if ((xmlNode != NULL) && (xmlNode->getTextContent().equalsIgnoreCase("no"))) {
01388 allowSelfTriggering = false;
01389 }
01390 }
01391
01392 ObjectCollection* children = node->getChildTags();
01393 if ((children == NULL) || (children->getCount() == 0))
01394 return true;
01395
01396 PhaseSpec* phaseSpec;
01397 JString tag;
01398 for (int n=0; n<children->getCount(); n++) {
01399 xmlNode = (XMLNode*) children->get(n);
01400 if (xmlNode != NULL) {
01401 tag = xmlNode->getTag();
01402 if (tag.equalsIgnoreCase("phase")) {
01403 phaseSpec = new PhaseSpec();
01404 phaseSpec->priority = priority;
01405 phaseSpec->allowSelfTriggering = allowSelfTriggering;
01406 phaseSpec->fromXML(xmlNode);
01407 phaseSpec->moduleName = moduleName;
01408 phaseSpec->context = name;
01409 phases->add(phaseSpec);
01410 }
01411 else if (tag.containsIgnoreCase("trigger") || tag.containsIgnoreCase("retrieve") ||
01412 tag.containsIgnoreCase("crank") || tag.containsIgnoreCase("post") || tag.containsIgnoreCase("stream") ) {
01413
01414 phaseSpec = new PhaseSpec();
01415 phaseSpec->priority = priority;
01416 phaseSpec->allowSelfTriggering = allowSelfTriggering;
01417 phaseSpec->name = "Default";
01418 phaseSpec->moduleName = moduleName;
01419 phaseSpec->context = name;
01420 phases->add(phaseSpec);
01421 phaseSpec->fromXML(node);
01422 break;
01423 }
01424 }
01425 }
01426
01427 currentPhase = (PhaseSpec*) phases->get(currentPhaseNum);
01428 return true;
01429 }
01430
01431 JString ContextSpec::toXML() {
01432
01433 JString xml;
01434
01435 if (allowSelfTriggering)
01436 xml += JString::format("<allowselftriggering>Yes</allowselftriggering>\n");
01437
01438 PhaseSpec* phaseSpec;
01439 for (int n=0; n<phases->getCount(); n++) {
01440 phaseSpec = (PhaseSpec*) phases->get(n);
01441 if (phaseSpec != NULL) {
01442 xml += phaseSpec->toXML() + "\n";
01443 }
01444 }
01445
01446 return JString::format("<context name=\"%s\" module=\"%s\">\n%s</context>",
01447 (char*) name.xmlStringEncode(), (char*) moduleName.xmlStringEncode(), (char*) xml.indentXML());
01448 }
01449
01450 bool ContextSpec::reset() {
01451 currentPhaseNum = 0;
01452 calcCurrentPhases();
01453 return true;
01454 }
01455
01456 bool ContextSpec::calcCurrentPhases() {
01457
01458
01459
01460
01461
01462 currentActivePhases->removeAll();
01463 PhaseSpec* spec;
01464 for (int n=0; n<phases->getCount(); n++) {
01465 if ( (spec = (PhaseSpec*) phases->get(n)) != NULL) {
01466 if ( (n == currentPhaseNum) || (spec->containsGlobalTrigger()) )
01467 currentActivePhases->add(spec);
01468 }
01469 }
01470
01471 return true;
01472 }
01473
01474
01475 bool ContextSpec::setCurrentContexts(ObjectDictionary* newContexts) {
01476
01477
01478 currentContexts->removeAll();
01479 currentContexts->copyAll(newContexts);
01480 if ( (!wasActive) && (isActive()) ) {
01481 wasActive = true;
01482 reset();
01483 }
01484 return true;
01485 }
01486
01487 bool ContextSpec::isActive() {
01488 if (currentContexts == NULL) {
01489
01490 return false;
01491 }
01492 JString key = ownContext[0];
01493 if (!currentContexts->contains(key)) {
01494
01495 return false;
01496 }
01497 DotString* cname = (DotString*) currentContexts->get(key);
01498 if (cname == NULL)
01499 return false;
01500 return ownContext.isPartOf(*cname);
01501
01502 }
01503
01504 ObjectCollection* ContextSpec::getActivePhases() {
01505 if (currentActivePhases->getCount() == 0)
01506 return NULL;
01507 ObjectCollection* coll = new ObjectCollection();
01508 coll->noDelete();
01509 coll->addAll(currentActivePhases);
01510 return coll;
01511
01512 }
01513
01514 ObjectCollection* ContextSpec::getAllPhases() {
01515 if (phases->getCount() == 0)
01516 return NULL;
01517 ObjectCollection* coll = new ObjectCollection();
01518 coll->noDelete();
01519 coll->addAll(phases);
01520 return coll;
01521
01522 }
01523
01524 bool ContextSpec::switchPhase() {
01525
01526 if (!isActive()) return false;
01527
01528 currentPhaseNum++;
01529
01530 if (currentPhaseNum >= phases->getCount())
01531 currentPhaseNum = 0;
01532
01533 calcCurrentPhases();
01534
01535 return true;
01536 }
01537
01538
01539 JString ContextSpec::toHTML() {
01540
01541 JString html = JString::format("Context Name: <I>%s</I>", (char*) name);
01542
01543 PhaseSpec* phaseSpec;
01544 ObjectCollection* activePhases = getActivePhases();
01545
01546 if (activePhases == NULL) {
01547 html += "No Active Phase\n";
01548 }
01549 else if (activePhases->getCount() == 0) {
01550 html += "No Active Phase\n";
01551 delete(activePhases);
01552 }
01553 else {
01554 for (int n=0; n<activePhases->getCount(); n++) {
01555 phaseSpec = (PhaseSpec*) activePhases->get(n);
01556 if (phaseSpec != NULL) {
01557 html += JString("<BR>\n") + phaseSpec->toHTML();
01558 }
01559 }
01560 }
01561
01562 return html;
01563 }
01564
01565
01566
01567
01568
01569
01570
01571
01572 long ContextSpec::getBinarySize(int chunk) {
01573 if (phases == NULL)
01574 return 0;
01575 return phases->getBinarySize(chunk);
01576 }
01577
01578
01579 int ContextSpec::getBinaryChunkCount() {
01580 if (phases == NULL)
01581 return 0;
01582 return phases->getBinaryChunkCount();
01583 }
01584
01585
01586 long ContextSpec::toBinaryBuffer(int chunk, char* buffer, int maxlen) {
01587 if (phases == NULL)
01588 return false;
01589 return phases->toBinaryBuffer(chunk, buffer, maxlen);
01590 }
01591
01592
01593 bool ContextSpec::fromBinaryBuffer(int chunk, char* buffer, long len) {
01594 if (phases == NULL)
01595 return false;
01596 return phases->fromBinaryBuffer(chunk, buffer, len);
01597 }
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618 ModuleSpec::ModuleSpec() {
01619 exec = NULL;
01620 currentContexts = new ObjectDictionary();
01621 contexts = new ObjectDictionary();
01622 priority = 0;
01623 allowSelfTriggering = false;
01624 getTriggersCache = new ObjectDictionary();
01625
01626 parameters = new ObjectDictionary();
01627 verbose = 0;
01628 recordOverwrite = false;
01629 }
01630
01631 ModuleSpec::ModuleSpec(const JString& xml) {
01632 exec = NULL;
01633 currentContexts = new ObjectDictionary();
01634 contexts = new ObjectDictionary();
01635 priority = 0;
01636 allowSelfTriggering = false;
01637 getTriggersCache = new ObjectDictionary();
01638
01639 parameters = new ObjectDictionary();
01640 verbose = 0;
01641 recordOverwrite = false;
01642 fromXML(xml);
01643 }
01644
01645 ModuleSpec::ModuleSpec(XMLNode* node) {
01646 exec = NULL;
01647 currentContexts = new ObjectDictionary();
01648 contexts = new ObjectDictionary();
01649 priority = 0;
01650 allowSelfTriggering = false;
01651 getTriggersCache = new ObjectDictionary();
01652
01653 parameters = new ObjectDictionary();
01654 verbose = 0;
01655 recordOverwrite = false;
01656 fromXML(node);
01657 }
01658
01659 ModuleSpec::~ModuleSpec() {
01660 delete(currentContexts);
01661 delete(contexts);
01662 delete(parameters);
01663
01664 delete(getTriggersCache);
01665 delete(exec);
01666 }
01667
01668
01669 unsigned long ModuleSpec::getPayloadSize() const {
01670 unsigned long payloadSize = moduleName.getPayloadSize() + description.getPayloadSize() + type.getPayloadSize() +
01671 remote.getPayloadSize() + share.getPayloadSize() + configXML.getPayloadSize() +
01672 plugFunction.getPayloadSize() + currentContextsCacheString.getPayloadSize();
01673
01674 if (getTriggersCache != NULL) payloadSize += getTriggersCache->getPayloadSize();
01675 if (currentContexts != NULL) payloadSize += currentContexts->getPayloadSize();
01676 if (parameters != NULL) payloadSize += parameters->getPayloadSize();
01677 if (exec != NULL) payloadSize += exec->getPayloadSize();
01678
01679 return payloadSize;
01680 }
01681
01682 Object* ModuleSpec::clone() const {
01683 ModuleSpec* spec = new ModuleSpec();
01684 spec->description = this->description;
01685 spec->type = this->type;
01686 spec->moduleName = this->moduleName;
01687 spec->remote = this->remote;
01688 spec->share = this->share;
01689 spec->priority = this->priority;
01690 spec->verbose = this->verbose;
01691 spec->configXML = this->configXML;
01692 spec->recordStorage = this->recordStorage;
01693 spec->recordOverwrite = this->recordOverwrite;
01694 spec->allowSelfTriggering = this->allowSelfTriggering;
01695 spec->contexts->copyAll(contexts);
01696 spec->parameters->copyAll(parameters);
01697 if (exec != NULL)
01698 spec->exec = (ExecutableSpec*) this->exec->clone();
01699 return spec;
01700 }
01701
01702 bool ModuleSpec::fromXML(const JString& xml) {
01703
01704 if (xml.length() == 0)
01705 return false;
01706
01707 XMLParser* xmlParser = new XMLParser();
01708 xmlParser->parse(xml);
01709 bool ret = fromXML(xmlParser->getRootNode());
01710 delete(xmlParser);
01711 return ret;
01712 }
01713
01714 bool ModuleSpec::resetCache() {
01715 getTriggersCache->removeAll();
01716 return true;
01717 }
01718
01719 bool ModuleSpec::fromXML(XMLNode* node) {
01720
01721 if ( (node == NULL) ||
01722 ( (!node->getTag().equalsIgnoreCase("module")) && (!node->getTag().equalsIgnoreCase("serviceprovider")) ) )
01723 return false;
01724
01725 parameters->removeAll();
01726 contexts->removeAll();
01727 getTriggersCache->removeAll();
01728
01729 moduleName = node->findAttr("name");
01730
01731 type = node->findAttr("type");
01732
01733 if (node->hasAttribute("share"))
01734 share = node->findAttr("share");
01735 else
01736 share = node->findAttr("shareresources");
01737
01738 if (node->hasAttribute("remote"))
01739 remote = node->findAttr("remote");
01740 else
01741 remote = node->findAttr("satellite");
01742
01743 if (node->hasAttribute("priority"))
01744 priority = node->findAttr("priority").toDouble();
01745
01746 plugFunction = node->findAttr("plug");
01747
01748 if (node->hasAttribute("verbose"))
01749 verbose = node->findAttr("verbose").toInt();
01750
01751 XMLNode* xmlNode = node->getChildNode("description");
01752 if (xmlNode == NULL)
01753 description = "";
01754 else
01755 description = xmlNode->getTextContent();
01756
01757 xmlNode = node->getChildNode("record");
01758 if (xmlNode == NULL)
01759 recordStorage = "";
01760 else {
01761 recordStorage = xmlNode->getAttribute("storage");
01762 recordOverwrite = xmlNode->getAttribute("overwrite").toBool();
01763 }
01764
01765 configXML = "";
01766 xmlNode = node->getChildNode("config");
01767 if (xmlNode == NULL)
01768 xmlNode = node->getChildNode("setup");
01769 if (xmlNode != NULL) {
01770
01771 if (xmlNode->hasAttribute("file"))
01772 configXML = JFile::readAFileASCII(xmlNode->getAttribute("file"));
01773 else
01774 configXML = xmlNode->toXMLChildrenOnly();
01775 }
01776
01777 ObjectDictionary* moduleParameters = Parameter::getParameterCollectionFromNode(node->getChildNode("parameters"));
01778 if (moduleParameters != NULL) {
01779 delete(parameters);
01780 parameters = moduleParameters;
01781 }
01782 moduleParameters = Parameter::getParameterCollectionFromNode(node->getChildNode("parameters"));
01783 if (moduleParameters != NULL) {
01784 parameters->addAll(moduleParameters);
01785 moduleParameters->removeAllNoDelete();
01786 delete(moduleParameters);
01787 }
01788 Parameter* parameter;
01789 ObjectCollection paramNodes = node->getChildNodes("parameter");
01790 for (XMLNode* paramNode = (XMLNode*) paramNodes.getFirst(); paramNode != NULL; paramNode = (XMLNode*) paramNodes.getNext()) {
01791 parameter = new Parameter(paramNode);
01792 if (parameter->name.length() > 0) {
01793 parameters->put(parameter->name, parameter);
01794 }
01795 else {
01796 delete(parameter);
01797 }
01798 }
01799
01800 if (node->getAttribute("allowselftriggering").equalsIgnoreCase("yes")) {
01801 allowSelfTriggering = true;
01802 }
01803 else {
01804 xmlNode = node->getChildNode("allowselftriggering");
01805 if ((xmlNode != NULL) && (xmlNode->getTextContent().equalsIgnoreCase("yes"))) {
01806 allowSelfTriggering = true;
01807 }
01808 }
01809
01810 xmlNode = node->getChildNode("executable");
01811 if (xmlNode != NULL) {
01812 this->exec = new ExecutableSpec(xmlNode);
01813 }
01814
01815 XMLNode* specNode = node->getChildNode("spec");
01816 if (specNode == NULL) {
01817 specNode = node;
01818
01819
01820 }
01821
01822 ObjectCollection* children = specNode->getChildTags();
01823 if ((children == NULL) || (children->getCount() == 0)) {
01824
01825 return true;
01826 }
01827
01828 JString tag;
01829 JString contextName;
01830
01831 ContextSpec* contextSpec = NULL;
01832 PhaseSpec* phaseSpec = NULL;
01833
01834 for (int n=0; n<children->getCount(); n++) {
01835 xmlNode = (XMLNode*) children->get(n);
01836 if (xmlNode != NULL) {
01837 tag = xmlNode->getTag();
01838 if (tag.equalsIgnoreCase("context")) {
01839
01840 contextName = xmlNode->findAttr("name");
01841 if (contextName.length() > 0) {
01842 contextSpec = new ContextSpec();
01843 contextSpec->priority = priority;
01844
01845
01846 contextSpec->moduleName = moduleName;
01847 if (!contextSpec->allowSelfTriggering)
01848 contextSpec->allowSelfTriggering = allowSelfTriggering;
01849 contextSpec->fromXML(xmlNode);
01850 contexts->put(contextName, contextSpec);
01851 }
01852 }
01853 else if (tag.equalsIgnoreCase("phase")) {
01854
01855 if (contextSpec == NULL) {
01856 contextSpec = new ContextSpec();
01857 contextSpec->priority = priority;
01858 contextSpec->name = "Psyclone.System.Ready";
01859 contextSpec->ownContext = contextSpec->name.toDotString();
01860 contextSpec->moduleName = moduleName;
01861 contextSpec->allowSelfTriggering = allowSelfTriggering;
01862 contexts->put(contextSpec->name, contextSpec);
01863 }
01864
01865 phaseSpec = new PhaseSpec();
01866 phaseSpec->priority = priority;
01867 phaseSpec->allowSelfTriggering = allowSelfTriggering;
01868 phaseSpec->fromXML(xmlNode);
01869 phaseSpec->moduleName = moduleName;
01870 phaseSpec->context = contextSpec->name;
01871 contextSpec->phases->add(phaseSpec);
01872 }
01873 else if (tag.containsIgnoreCase("trigger") || tag.containsIgnoreCase("retrieve") ||
01874 tag.containsIgnoreCase("crank") || tag.containsIgnoreCase("post") || tag.containsIgnoreCase("stream") || tag.containsIgnoreCase("streams") ) {
01875
01876 if (contextSpec == NULL) {
01877 contextSpec = new ContextSpec();
01878 contextSpec->priority = priority;
01879 contextSpec->name = "Psyclone.System.Ready";
01880 contextSpec->ownContext = contextSpec->name.toDotString();
01881 contextSpec->moduleName = moduleName;
01882 contextSpec->allowSelfTriggering = allowSelfTriggering;
01883 contexts->put(contextSpec->name, contextSpec);
01884 phaseSpec = new PhaseSpec();
01885 phaseSpec->priority = priority;
01886 phaseSpec->allowSelfTriggering = allowSelfTriggering;
01887 phaseSpec->name = "Default";
01888 phaseSpec->moduleName = moduleName;
01889 phaseSpec->context = contextSpec->name;
01890 contextSpec->phases->add(phaseSpec);
01891 }
01892 phaseSpec->fromXML(specNode);
01893 return true;
01894 }
01895 }
01896 }
01897
01898 return true;
01899 }
01900
01901 Collection ModuleSpec::getContextNames() {
01902 Collection names;
01903 ContextSpec* contextSpec;
01904 for (int n=0; n<contexts->getCount(); n++) {
01905 contextSpec = (ContextSpec*) contexts->get(n);
01906 if (contextSpec != NULL) {
01907 names.add(contextSpec->name);
01908 }
01909 }
01910 return names;
01911 }
01912
01913 bool ModuleSpec::hasCranks() {
01914
01915 ContextSpec* contextSpec;
01916 PhaseSpec* phaseSpec;
01917 for (int n=0; n<contexts->getCount(); n++) {
01918 if ( (contextSpec = (ContextSpec*) contexts->get(n)) != NULL) {
01919 for (int m=0; n<contextSpec->phases->getCount(); n++) {
01920 if ( (phaseSpec = (PhaseSpec*) contextSpec->phases->get(n)) != NULL) {
01921 if (phaseSpec->cranks->getCount() > 0)
01922 return true;
01923 }
01924 }
01925 }
01926 }
01927 return false;
01928 }
01929
01930
01931 JString ModuleSpec::toXML() {
01932 JString xml, subxml;
01933 int n;
01934
01935 if (exec != NULL)
01936 xml += exec->toXML() + "\n";
01937
01938 if (description.length() > 0)
01939 xml += JString::format("<description>%s</description>\n", (char*) description.xmlStringEncode());
01940
01941 if (allowSelfTriggering)
01942 xml += JString::format("<allowselftriggering>Yes</allowselftriggering>\n");
01943
01944 if (recordStorage.length() > 0)
01945 xml += JString::format("<record storage=\"%s\" overwrite=\"%s\">\n", (char*) recordStorage, (char*) JString(recordOverwrite));
01946
01947 Parameter* parameter;
01948 for (n=0; n<parameters->getCount(); n++) {
01949 parameter = (Parameter*) parameters->get(n);
01950 if (parameter != NULL)
01951 xml += JString::format("%s\n", (char*) parameter->toXML());
01952
01953 }
01954
01955
01956
01957
01958
01959 subxml = "";
01960 ContextSpec* contextSpec;
01961 for (n=0; n<contexts->getCount(); n++) {
01962 contextSpec = (ContextSpec*) contexts->get(n);
01963 if (contextSpec != NULL) {
01964 subxml += contextSpec->toXML() + "\n";
01965 }
01966 }
01967
01968 JString location;
01969 if (remote.length() > 0)
01970 location = JString::format("satellite=\"%s\" ", (char*) remote.xmlStringEncode());
01971 if (share.length() > 0)
01972 location += JString::format("shareresources=\"%s\" ", (char*) share.xmlStringEncode());
01973
01974 xml += JString::format("<spec>\n%s</spec>", (char*) subxml.indentXML());
01975
01976 if (configXML.length() > 0) {
01977 xml += JString::format("\n<config>\n%s</config>", (char*) configXML.indentXML());
01978 }
01979
01980 if (plugFunction.length() > 0)
01981 return JString::format("<module name=\"%s\" type=\"%s\" plug=\"%s\" priority=\"%.1f\" verbose=\"%d\" %s>\n%s</module>",
01982 (char*) moduleName.xmlStringEncode(), (char*) type.xmlStringEncode(), (char*) plugFunction.xmlStringEncode(), priority, verbose, (char*) location, (char*) xml.indentXML());
01983 else
01984 return JString::format("<module name=\"%s\" type=\"%s\" priority=\"%.1f\" verbose=\"%d\" %s>\n%s</module>",
01985 (char*) moduleName.xmlStringEncode(), (char*) type.xmlStringEncode(), priority, verbose, (char*) location, (char*) xml.indentXML());
01986 }
01987
01988 bool ModuleSpec::switchPhase() {
01989
01990 ContextSpec* contextSpec;
01991 ObjectCollection* activeContexts = getActiveContexts();
01992 for (int n=0; n<activeContexts->getCount(); n++) {
01993 contextSpec = (ContextSpec*) activeContexts->get(n);
01994 if (contextSpec != NULL)
01995 contextSpec->switchPhase();
01996 }
01997 delete(activeContexts);
01998 resetCache();
01999 return true;
02000 }
02001
02002 bool ModuleSpec::setCurrentContexts(ObjectDictionary* newContexts) {
02003
02004 currentContexts->removeAll();
02005 currentContexts->copyAll(newContexts);
02006 ContextSpec* contextSpec;
02007
02008 for (int n=0; n<contexts->getCount(); n++) {
02009 contextSpec = (ContextSpec*) contexts->get(n);
02010 if (contextSpec != NULL)
02011 contextSpec->setCurrentContexts(newContexts);
02012 }
02013 currentContextsCacheString = currentContexts->printListLine("-");
02014 return true;
02015 }
02016
02017 bool ModuleSpec::isCurrentlyTriggeredBy(JString wb, JString type) {
02018
02019 ObjectCollection* phases = getTriggersFor(wb, type);
02020 if (phases->getCount() == 0) {
02021 delete(phases);
02022 return false;
02023 }
02024 else {
02025 delete(phases);
02026 return true;
02027 }
02028 }
02029
02030 ObjectCollection* ModuleSpec::getTriggersFor(JString wb, JString type) {
02031
02032 if (currentContexts == NULL)
02033 return NULL;
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043 JString cacheString = JString::format("%s+%s+%s", (char*) currentContextsCacheString, (char*) wb, (char*) type);
02044
02045 ObjectCollection* copy = new ObjectCollection();
02046 copy->noDelete();
02047
02048 ObjectCollection* phases = (ObjectCollection*) getTriggersCache->get(cacheString);
02049 if (phases != NULL) {
02050 copy->addAll(phases);
02051 return copy;
02052 }
02053
02054 phases = new ObjectCollection();
02055 phases->noDelete();
02056
02057 ObjectCollection* activePhases;
02058 if (wb.length() > 0)
02059 activePhases = getActivePhases();
02060 else
02061 activePhases = getAllPhases();
02062
02063
02064
02065
02066
02067 PhaseSpec* phaseSpec;
02068
02069 TriggerSpec* trigger;
02070 for (int i=0; i < activePhases->getCount(); i++) {
02071 phaseSpec = (PhaseSpec*) activePhases->get(i);
02072 if (phaseSpec != NULL) {
02073 for (int n=0; n<phaseSpec->triggers->getCount(); n++) {
02074 trigger = (TriggerSpec*) phaseSpec->triggers->get(n);
02075 if (trigger != NULL) {
02076 if ( ( (wb.length() == 0) ||
02077 (trigger->from.length() == 0) ||
02078 (trigger->from.equalsIgnoreCase("any")) ||
02079 (trigger->from.equalsIgnoreCase("*")) ||
02080 (trigger->from.equalsIgnoreCase(wb)) ) &&
02081 (trigger->type.equals(type)) ) {
02082
02083 phases->add(phaseSpec);
02084 }
02085 }
02086 }
02087 }
02088 }
02089
02090
02091
02092
02093 delete(activePhases);
02094
02095 copy->addAll(phases);
02096 getTriggersCache->put(cacheString, copy);
02097 if (getTriggersCache->getCount() > 100)
02098 getTriggersCache->removeFirst();
02099
02100 return phases;
02101 }
02102
02103 ObjectCollection* ModuleSpec::getActiveContexts() {
02104
02105 ObjectCollection* activeContexts = new ObjectCollection();
02106 activeContexts->noDelete();
02107
02108 ContextSpec* contextSpec;
02109 for (int n=0; n<contexts->getCount(); n++) {
02110 contextSpec = (ContextSpec*) contexts->get(n);
02111 if (contextSpec != NULL) {
02112 if (contextSpec->isActive()) {
02113 activeContexts->add(contextSpec);
02114 }
02115 }
02116 }
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144 return activeContexts;
02145 }
02146
02147 PhaseSpec* ModuleSpec::getFirstActivePhase() {
02148 ObjectCollection* activeContexts = getActiveContexts();
02149
02150 PhaseSpec* phaseSpec = NULL;
02151 ObjectCollection* localPhases;
02152 ContextSpec* contextSpec;
02153 for (int n=0; n<activeContexts->getCount(); n++) {
02154 contextSpec = (ContextSpec*) activeContexts->get(n);
02155 if (contextSpec != NULL) {
02156 localPhases = contextSpec->getActivePhases();
02157 if (localPhases != NULL) {
02158 phaseSpec = (PhaseSpec*) localPhases->getFirst();
02159 delete(localPhases);
02160 if (phaseSpec != NULL)
02161 break;
02162 }
02163 }
02164 }
02165 delete(activeContexts);
02166 return phaseSpec;
02167 }
02168
02169 ObjectCollection* ModuleSpec::getActivePhases() {
02170
02171 ObjectCollection* activePhases = new ObjectCollection();
02172 activePhases->noDelete();
02173
02174 ObjectCollection* localPhases;
02175
02176 ObjectCollection* activeContexts = getActiveContexts();
02177
02178 ContextSpec* contextSpec;
02179 for (int n=0; n<activeContexts->getCount(); n++) {
02180 contextSpec = (ContextSpec*) activeContexts->get(n);
02181 if (contextSpec != NULL) {
02182 localPhases = contextSpec->getActivePhases();
02183 if (localPhases != NULL) {
02184 activePhases->addAll(localPhases);
02185 delete(localPhases);
02186 }
02187 }
02188 }
02189 delete(activeContexts);
02190 return activePhases;
02191 }
02192
02193 ObjectCollection* ModuleSpec::getAllPhases() {
02194
02195 ObjectCollection* allPhases = new ObjectCollection();
02196 allPhases->noDelete();
02197
02198 ObjectCollection* localPhases;
02199
02200 ObjectCollection* activeContexts = getActiveContexts();
02201
02202 ContextSpec* contextSpec;
02203 for (int n=0; n<activeContexts->getCount(); n++) {
02204 contextSpec = (ContextSpec*) activeContexts->get(n);
02205 if (contextSpec != NULL) {
02206 localPhases = contextSpec->getAllPhases();
02207 if (localPhases != NULL) {
02208 allPhases->addAll(localPhases);
02209 delete(localPhases);
02210 }
02211 }
02212 }
02213 delete(activeContexts);
02214 return allPhases;
02215 }
02216
02217 Collection ModuleSpec::getReferredWhiteboards() {
02218
02219 Collection whiteboardNames;
02220
02221 int i, j, n;
02222 ContextSpec* contextSpec;
02223 PhaseSpec* phaseSpec;
02224 TriggerSpec* trigger;
02225 RetrieveSpec* retrieve;
02226 PostSpec* post;
02227 for (j=0; j < contexts->getCount(); j++) {
02228 if ( (contextSpec = (ContextSpec*) contexts->get(j)) != NULL) {
02229 for (i=0; i < contextSpec->phases->getCount(); i++) {
02230 if ( (phaseSpec = (PhaseSpec*) contextSpec->phases->get(i)) != NULL) {
02231 for (n=0; n<phaseSpec->triggers->getCount(); n++) {
02232 if ( (trigger = (TriggerSpec*) phaseSpec->triggers->get(n)) != NULL) {
02233 if (trigger->from.length() > 0)
02234 if (!whiteboardNames.contains(trigger->from))
02235 whiteboardNames.add(trigger->from);
02236 }
02237 }
02238 for (n=0; n<phaseSpec->retrieves->getCount(); n++) {
02239 if ( (retrieve = (RetrieveSpec*) phaseSpec->retrieves->get(n)) != NULL) {
02240 if (retrieve->from.length() > 0)
02241 if (!whiteboardNames.contains(retrieve->from))
02242 whiteboardNames.add(retrieve->from);
02243 }
02244 }
02245 for (n=0; n<phaseSpec->posts->getCount(); n++) {
02246 if ( (post = (PostSpec*) phaseSpec->posts->get(n)) != NULL) {
02247 if (post->to.length() > 0)
02248 if (!whiteboardNames.contains(post->to))
02249 whiteboardNames.add(post->to);
02250 }
02251 }
02252 }
02253 }
02254 }
02255 }
02256
02257 return whiteboardNames;
02258 }
02259
02260 Collection ModuleSpec::getReferredStreams() {
02261
02262 Collection streamNames;
02263
02264 int i, j, n;
02265 ContextSpec* contextSpec;
02266 PhaseSpec* phaseSpec;
02267 StreamAccess* streamAccess;
02268 for (j=0; j < contexts->getCount(); j++) {
02269 if ( (contextSpec = (ContextSpec*) contexts->get(j)) != NULL) {
02270 for (i=0; i < contextSpec->phases->getCount(); i++) {
02271 if ( (phaseSpec = (PhaseSpec*) contextSpec->phases->get(i)) != NULL) {
02272 for (n=0; n<phaseSpec->streams->getCount(); n++) {
02273 if ( (streamAccess = (StreamAccess*) phaseSpec->streams->get(n)) != NULL) {
02274 if (streamAccess->source.length() > 0)
02275 if (!streamNames.contains(streamAccess->source))
02276 streamNames.add(streamAccess->source);
02277 }
02278 }
02279 }
02280 }
02281 }
02282 }
02283
02284 return streamNames;
02285 }
02286
02287 JString ModuleSpec::toHTML() {
02288
02289 JString html;
02290
02291 if (contexts->getCount() == 0)
02292 html = JString::format("Module: <I>%s</I> has no contexts\n", (char*) moduleName);
02293 else if (contexts->getCount() == 1)
02294 html = JString::format("Module: <I>%s</I> has %d parameters and one context\n", (char*) moduleName, parameters->getCount());
02295 else
02296 html = JString::format("Module: <I>%s</I> has %d parameters and %d contexts\n", (char*) moduleName, parameters->getCount(), contexts->getCount());
02297
02298
02299 ContextSpec* contextSpec;
02300 PhaseSpec *phaseSpec;
02301 JString contextName;
02302 ObjectCollection phases;
02303
02304 for (int n=0; n<contexts->getCount(); n++) {
02305 contextSpec = (ContextSpec*) contexts->get(n);
02306 if (contextSpec != NULL) {
02307
02308
02309 if (contextSpec->phases->getCount() == 0)
02310 html += JString::format("Context: <I>%s</I> has no phases\n", (char*) contextName);
02311 else if (contextSpec->phases->getCount() == 1)
02312 html += JString::format("Context: <I>%s</I> has one phase\n", (char*) contextName);
02313 else
02314 html += JString::format("Context: <I>%s</I> has %d phases\n", (char*) contextName, contextSpec->phases->getCount());
02315
02316 for (int m=0; m<contextSpec->phases->getCount(); m++) {
02317 phaseSpec = (PhaseSpec*) contextSpec->phases->get(m);
02318 if (phaseSpec != NULL) {
02319 html += phaseSpec->toHTML();
02320 html += "<hr>";
02321 }
02322 }
02323 }
02324 }
02325
02326 return html;
02327 }
02328
02329
02330 JString ModuleSpec::toHTMLCurrent() {
02331
02332
02333
02334 JString html;
02335
02336 html += "<table width=\"100%\" border=\"0\">";
02337 html += "<tr><td width=\"10\"></td><td width=\"15\"></td><td width=\"8000\"></td><td width=\"20\"></td></tr>";
02338
02339 html += "<tr><td></td>";
02340
02341 ObjectCollection* activeContexts = getActiveContexts();
02342 if (activeContexts->getCount() == 0) {
02343 html += "<td colspan=\"3\" bgcolor=\"#eeeeee\">";
02344 html += JString::format("<font color=\"#0000ff\" size=\"4\">Module: <I>%s</I> is currently out of context</font>\n", (char*) moduleName);
02345 html += "</td></tr></table>";
02346 delete(activeContexts);
02347 return html;
02348 }
02349
02350 html += "<td colspan=\"2\" bgcolor=\"#eeeeee\">";
02351 html += JString::format("<font color=\"#0000ff\" size=\"4\">Module: <I>%s</I></font></td>\n", (char*) moduleName);
02352
02353 html += JString::format("<td align=\"right\"><input type=\"submit\" name=\"switchphase_%s\" value=\"Change Phase\"></td></tr>\n", (char*) moduleName);
02354
02355 ObjectCollection* activePhases = getActivePhases();
02356 if (activePhases->getCount() == 0) {
02357 html += JString::format("<tr><td></td><td></td><td><font color=\"#00ff00\" size=\"4\">No active contexts...</font>\n");
02358 html += "</td><td></td></tr></table>";
02359 delete(activePhases);
02360 delete(activeContexts);
02361 return html;
02362 }
02363
02364 PhaseSpec *phaseSpec;
02365 for (int i=0; i<activePhases->getCount(); i++) {
02366 phaseSpec = (PhaseSpec*) activePhases->get(i);
02367 if (phaseSpec != NULL) {
02368 html += "<tr><td></td><td></td><td colspan=\"2\">";
02369
02370 html += JString("<font color=\"#0000ff\" size=\"3\">Active ") + phaseSpec->toHTML();
02371 html += "</font></td></tr>";
02372 }
02373 }
02374 html += "</table>";
02375
02376 delete(activePhases);
02377 delete(activeContexts);
02378 return html;
02379 }
02380
02381
02382
02383
02384
02385
02386
02387
02388 long ModuleSpec::getBinarySize(int chunk) {
02389 if (contexts == NULL)
02390 return 0;
02391 return contexts->getBinarySize(chunk);
02392 }
02393
02394
02395 int ModuleSpec::getBinaryChunkCount() {
02396 if (contexts == NULL)
02397 return 0;
02398 return contexts->getBinaryChunkCount();
02399 }
02400
02401
02402 long ModuleSpec::toBinaryBuffer(int chunk, char* buffer, int maxlen) {
02403 if (contexts == NULL)
02404 return false;
02405 return contexts->toBinaryBuffer(chunk, buffer, maxlen);
02406 }
02407
02408
02409 bool ModuleSpec::fromBinaryBuffer(int chunk, char* buffer, long len) {
02410 if (contexts == NULL)
02411 return false;
02412 return contexts->fromBinaryBuffer(chunk, buffer, len);
02413 }
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439 WhiteboardSpec::WhiteboardSpec() {
02440 streamSpecs = new ObjectDictionary();
02441 catalogSpecs = new ObjectDictionary();
02442 parameters = new ObjectDictionary();
02443 priority = 0;
02444 useLocalSystemInfo = false;
02445 }
02446
02447 WhiteboardSpec::WhiteboardSpec(const JString& xml) {
02448 streamSpecs = new ObjectDictionary();
02449 catalogSpecs = new ObjectDictionary();
02450 parameters = new ObjectDictionary();
02451 priority = 0;
02452 useLocalSystemInfo = false;
02453 fromXML(xml);
02454 }
02455
02456 WhiteboardSpec::WhiteboardSpec(XMLNode* node) {
02457 streamSpecs = new ObjectDictionary();
02458 catalogSpecs = new ObjectDictionary();
02459 parameters = new ObjectDictionary();
02460 priority = 0;
02461 useLocalSystemInfo = false;
02462 fromXML(node);
02463 }
02464
02465 WhiteboardSpec::~WhiteboardSpec() {
02466 delete(streamSpecs);
02467 delete(catalogSpecs);
02468 delete(parameters);
02469 }
02470
02471
02472 unsigned long WhiteboardSpec::getPayloadSize() const {
02473 unsigned long payloadSize = whiteboardName.getPayloadSize() + description.getPayloadSize() + remote.getPayloadSize();
02474
02475 if (streamSpecs != NULL) payloadSize += streamSpecs->getPayloadSize();
02476 if (catalogSpecs != NULL) payloadSize += catalogSpecs->getPayloadSize();
02477
02478 return payloadSize;
02479 }
02480
02481 Object* WhiteboardSpec::clone() const {
02482 WhiteboardSpec* spec = new WhiteboardSpec();
02483 spec->description = this->description;
02484 spec->whiteboardName = this->whiteboardName;
02485
02486 spec->remote = this->remote;
02487 spec->priority = this->priority;
02488 spec->streamSpecs->copyAll(streamSpecs);
02489 spec->catalogSpecs->copyAll(catalogSpecs);
02490 spec->parameters->copyAll(parameters);
02491 spec->useLocalSystemInfo = useLocalSystemInfo;
02492 return spec;
02493 }
02494
02495 bool WhiteboardSpec::fromXML(const JString& xml) {
02496
02497 if (xml.length() == 0)
02498 return false;
02499
02500 XMLParser* xmlParser = new XMLParser();
02501 xmlParser->parse(xml);
02502 bool ret = fromXML(xmlParser->getRootNode());
02503 delete(xmlParser);
02504 return ret;
02505 }
02506
02507 bool WhiteboardSpec::fromXML(XMLNode* node) {
02508
02509 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("whiteboard")) )
02510 return false;
02511
02512 streamSpecs->removeAll();
02513
02514 whiteboardName = node->findAttr("name");
02515 if (node->hasAttribute("remote"))
02516 remote = node->findAttr("remote");
02517 else
02518 remote = node->findAttr("satellite");
02519 if (node->hasAttribute("priority"))
02520 priority = node->findAttr("priority").toDouble();
02521
02522 if (node->getAttribute("cachedglobalstate").equalsIgnoreCase("yes"))
02523 useLocalSystemInfo = true;
02524
02525 XMLNode* xmlNode = node->getChildNode("description");
02526 if (xmlNode == NULL)
02527 description = "";
02528 else
02529 description = xmlNode->getTextContent();
02530
02531 ObjectDictionary* myParameters = Parameter::getParameterCollectionFromNode(node->getChildNode("parameters"));
02532 if (myParameters != NULL) {
02533 delete(parameters);
02534 parameters = myParameters;
02535 }
02536 myParameters = Parameter::getParameterCollectionFromNode(node->getChildNode("parameters"));
02537 if (myParameters != NULL) {
02538 if (parameters == NULL)
02539 parameters = myParameters;
02540 else {
02541 parameters->addAll(myParameters);
02542 myParameters->removeAllNoDelete();
02543 delete(myParameters);
02544 }
02545 }
02546 Parameter* parameter;
02547 ObjectCollection paramNodes = node->getChildNodes("parameter");
02548 for (XMLNode* paramNode = (XMLNode*) paramNodes.getFirst(); paramNode != NULL; paramNode = (XMLNode*) paramNodes.getNext()) {
02549 parameter = new Parameter(paramNode);
02550 if (parameter->name.length() > 0) {
02551 if (parameters == NULL)
02552 parameters = new ObjectDictionary();
02553 parameters->put(parameter->name, parameter);
02554 }
02555 else {
02556 delete(parameter);
02557 }
02558 }
02559
02560 if (node->hasAttribute("maxcount")) {
02561 JString maxCount = node->findAttr("maxcount");
02562 if (maxCount.length() > 0) {
02563 parameter = (Parameter*) parameters->get("maxMessages");
02564 if (parameter == NULL) {
02565 parameter = new Parameter("maxMessages", "Integer", maxCount, maxCount);
02566 parameters->put("maxMessages", parameter);
02567 }
02568 else {
02569 parameter->set(maxCount);
02570 }
02571 }
02572 }
02573
02574 StreamSpec* streamSpec;
02575 xmlNode = node->getChildNode("streams");
02576 if (xmlNode == NULL)
02577 xmlNode = node->getChildNode("mediastreams");
02578 if (xmlNode != NULL) {
02579 ObjectCollection* col = xmlNode->getChildTags();
02580 if (col != NULL) {
02581 for (int m=0; m<col->getCount(); m++) {
02582 xmlNode = (XMLNode*) col->get(m);
02583 if (xmlNode != NULL) {
02584 streamSpec = new StreamSpec(xmlNode);
02585 streamSpec->parent = whiteboardName;
02586 streamSpecs->put(streamSpec->streamName, streamSpec);
02587 }
02588 }
02589 }
02590 }
02591
02592 ObjectCollection streamsNodes = node->getChildNodes("stream");
02593 for (XMLNode* streamsNode = (XMLNode*) streamsNodes.getFirst(); streamsNode != NULL; streamsNode = (XMLNode*) streamsNodes.getNext()) {
02594 streamSpec = new StreamSpec(streamsNode);
02595 streamSpec->parent = whiteboardName;
02596 streamSpecs->put(streamSpec->streamName, streamSpec);
02597 }
02598
02599 CatalogSpec* catalogSpec = NULL;
02600 xmlNode = node->getChildNode("catalogs");
02601 if (xmlNode != NULL) {
02602 ObjectCollection* col = xmlNode->getChildTags();
02603 if (col != NULL) {
02604 for (int m=0; m<col->getCount(); m++) {
02605 xmlNode = (XMLNode*) col->get(m);
02606 if (xmlNode != NULL) {
02607 catalogSpec = new CatalogSpec(xmlNode);
02608 catalogSpec->parent = whiteboardName;
02609 catalogSpecs->put(catalogSpec->name, catalogSpec);
02610 }
02611 }
02612 }
02613 }
02614
02615 ObjectCollection catalogsNodes = node->getChildNodes("catalog");
02616 for (XMLNode* catalogsNode = (XMLNode*) catalogsNodes.getFirst(); catalogsNode != NULL; catalogsNode = (XMLNode*) catalogsNodes.getNext()) {
02617 catalogSpec = new CatalogSpec(catalogsNode);
02618 catalogSpec->parent = whiteboardName;
02619 catalogSpecs->put(catalogSpec->name, catalogSpec);
02620 }
02621
02622 return true;
02623 }
02624
02625 JString WhiteboardSpec::toXML() {
02626 JString xml, subxml;
02627 int n;
02628
02629 if (description.length() > 0)
02630 xml += JString::format("<description>%s</description>\n", (char*) description.xmlStringEncode());
02631
02632 Parameter* parameter;
02633 for (n=0; n<parameters->getCount(); n++) {
02634 parameter = (Parameter*) parameters->get(n);
02635 if (parameter != NULL)
02636 xml += JString::format("%s\n", (char*) parameter->toXML());
02637
02638 }
02639
02640
02641
02642
02643
02644 subxml = "";
02645 StreamSpec* streamSpec;
02646 for (n=0; n<streamSpecs->getCount(); n++) {
02647 streamSpec = (StreamSpec*) streamSpecs->get(n);
02648 if (streamSpec != NULL) {
02649 subxml += streamSpec->toXML() + "\n";
02650 }
02651 }
02652 if (subxml.length() > 0)
02653 xml += JString::format("<streams>\n%s</streams>", (char*) subxml.indentXML());
02654
02655 subxml = "";
02656 CatalogSpec* catalogSpec;
02657 for (n=0; n<catalogSpecs->getCount(); n++) {
02658 catalogSpec = (CatalogSpec*) catalogSpecs->get(n);
02659 if (catalogSpec != NULL) {
02660 subxml += catalogSpec->toXML() + "\n";
02661 }
02662 }
02663 if (subxml.length() > 0)
02664 xml += JString::format("<catalogs>\n%s</catalogs>", (char*) subxml.indentXML());
02665
02666 JString location;
02667 if (remote.length() > 0)
02668 location = JString::format("satellite=\"%s\" ", (char*) remote.xmlStringEncode());
02669 if (useLocalSystemInfo)
02670 location += "cachedglobalstate=\"yes\" ";
02671
02672 if (xml.length() > 0) {
02673 return JString::format("<whiteboard name=\"%s\" priority=\"%.1f\" %s>\n%s</whiteboard>",
02674 (char*) whiteboardName.xmlStringEncode(), priority, (char*) location, (char*) xml.indentXML());
02675 }
02676
02677
02678 return JString::format("<whiteboard name=\"%s\" priority=\"%.1f\" %s></whiteboard>", (char*) whiteboardName.xmlStringEncode(), priority, (char*) location);
02679 }
02680
02681
02682
02683 JString WhiteboardSpec::toHTML() {
02684 JString html;
02685 return html;
02686 }
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709 StreamSpec::StreamSpec() {
02710 allowMultipleWriters = false;
02711 maxSize = 0;
02712 maxCount = 0;
02713 maxBackupCount = 0;
02714 }
02715
02716 StreamSpec::StreamSpec(const JString& xml) {
02717 allowMultipleWriters = false;
02718 maxSize = 0;
02719 maxCount = 0;
02720 maxBackupCount = 0;
02721 fromXML(xml);
02722 }
02723
02724 StreamSpec::StreamSpec(XMLNode* node) {
02725 allowMultipleWriters = false;
02726 maxSize = 0;
02727 maxCount = 0;
02728 maxBackupCount = 0;
02729 fromXML(node);
02730 }
02731
02732 StreamSpec::~StreamSpec() {
02733 }
02734
02735
02736 unsigned long StreamSpec::getPayloadSize() const {
02737 unsigned long payloadSize = streamName.getPayloadSize() + description.getPayloadSize() + parent.getPayloadSize() + remote.getPayloadSize();
02738 return payloadSize;
02739 }
02740
02741 Object* StreamSpec::clone() const {
02742 StreamSpec* spec = new StreamSpec();
02743 spec->description = this->description;
02744 spec->streamName = this->streamName;
02745 spec->maxSize = this->maxSize;
02746 spec->maxCount = this->maxCount;
02747 spec->maxBackupCount = this->maxBackupCount;
02748 spec->parent = this->parent;
02749 spec->remote = this->remote;
02750 spec->allowMultipleWriters = this->allowMultipleWriters;
02751 return spec;
02752 }
02753
02754 bool StreamSpec::fromXML(const JString& xml) {
02755
02756 if (xml.length() == 0)
02757 return false;
02758
02759 XMLParser* xmlParser = new XMLParser();
02760 xmlParser->parse(xml);
02761 bool ret = fromXML(xmlParser->getRootNode());
02762 delete(xmlParser);
02763 return ret;
02764 }
02765
02766 bool StreamSpec::fromXML(XMLNode* node) {
02767
02768 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("stream")) )
02769 return false;
02770
02771 streamName = node->findAttr("name");
02772 maxSize = node->findAttr("maxsize").toLong();
02773 maxCount = node->findAttr("maxcount").toLong();
02774 maxBackupCount = node->findAttr("maxbackupcount").toLong();
02775 allowMultipleWriters = node->getAttribute("allowmultiplewriters").equalsIgnoreCase("yes");
02776
02777 if (node->hasAttribute("remote"))
02778 remote = node->findAttr("remote");
02779 else
02780 remote = node->findAttr("satellite");
02781
02782 XMLNode* xmlNode = node->getChildNode("description");
02783 if (xmlNode == NULL)
02784 description = "";
02785 else
02786 description = xmlNode->getTextContent();
02787
02788 return true;
02789 }
02790
02791 JString StreamSpec::toXML() {
02792 JString xml;
02793
02794 if (description.length() > 0)
02795 xml += JString::format("<description>%s</description>\n", (char*) description.xmlStringEncode());
02796
02797 JString params;
02798 if (allowMultipleWriters)
02799 params = " allowmultiplewriters=\"yes\"";
02800
02801 if (xml.length() > 0) {
02802 return JString::format("<stream name=\"%s\" maxsize=\"%ld\" maxcount=\"%ld\" maxbackupcount=\"%ld\" satellite=\"%s\"%s>\n%s</stream>",
02803 (char*) streamName.xmlStringEncode(), maxSize, maxCount, maxBackupCount, (char*) remote, (char*) params, (char*) xml.indentXML());
02804 }
02805
02806 return JString::format("<stream name=\"%s\" maxsize=\"%ld\" maxcount=\"%ld\" maxbackupcount=\"%ld\" satellite=\"%s\"%s />",
02807 (char*) streamName.xmlStringEncode(), maxSize, maxCount, maxBackupCount, (char*) remote, (char*) params);
02808 }
02809
02810
02811
02812 JString StreamSpec::toHTML() {
02813 JString html;
02814 return html;
02815 }
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831 StreamAccess::StreamAccess() {
02832 }
02833
02834 StreamAccess::StreamAccess(const JString& xml) {
02835 fromXML(xml);
02836 }
02837
02838 StreamAccess::StreamAccess(XMLNode* node) {
02839 fromXML(node);
02840 }
02841
02842 StreamAccess::~StreamAccess() {
02843 }
02844
02845
02846 unsigned long StreamAccess::getPayloadSize() const {
02847 return alias.getPayloadSize() + source.getPayloadSize() + mode.getPayloadSize();
02848 }
02849
02850 Object* StreamAccess::clone() const {
02851 StreamAccess* spec = new StreamAccess();
02852 spec->alias = this->alias;
02853 spec->source = this->source;
02854 spec->mode = this->mode;
02855 return spec;
02856 }
02857
02858 bool StreamAccess::fromXML(const JString& xml) {
02859
02860 if (xml.length() == 0)
02861 return false;
02862
02863 XMLParser* xmlParser = new XMLParser();
02864 xmlParser->parse(xml);
02865 bool ret = fromXML(xmlParser->getRootNode());
02866 delete(xmlParser);
02867 return ret;
02868 }
02869
02870 bool StreamAccess::fromXML(XMLNode* node) {
02871
02872 if ( (node == NULL) || (!node->getTag().containsIgnoreCase("stream")) )
02873 return false;
02874
02875 mode = node->getTag();
02876 if (node->hasAttribute("alias"))
02877 alias = node->findAttr("alias");
02878 else
02879 alias = node->findAttr("name");
02880 source = node->findAttr("source");
02881 return true;
02882 }
02883
02884 JString StreamAccess::toXML() {
02885 return JString::format("<%s alias=\"%s\" source=\"%s\" />", (char*) mode, (char*) alias.xmlStringEncode(), (char*) source.xmlStringEncode());
02886 }
02887
02888
02889
02890 JString StreamAccess::toHTML() {
02891 JString html;
02892 return html;
02893 }
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907 CatalogSpec::CatalogSpec() {
02908 }
02909
02910 CatalogSpec::CatalogSpec(const JString& xml) {
02911 fromXML(xml);
02912 }
02913
02914 CatalogSpec::CatalogSpec(XMLNode* node) {
02915 fromXML(node);
02916 }
02917
02918 CatalogSpec::~CatalogSpec() {
02919 }
02920
02921
02922 unsigned long CatalogSpec::getPayloadSize() const {
02923 return name.getPayloadSize() + remote.getPayloadSize() + description.getPayloadSize() +
02924 parent.getPayloadSize() + queryhandler.getPayloadSize() + plug.getPayloadSize() +
02925 parameters.getPayloadSize();
02926 }
02927
02928 Object* CatalogSpec::clone() const {
02929 CatalogSpec* spec = new CatalogSpec();
02930 spec->description = this->description;
02931 spec->name = this->name;
02932 spec->remote = this->remote;
02933 spec->parent = this->parent;
02934 spec->queryhandler = this->queryhandler;
02935 spec->plug = this->plug;
02936 spec->parameters.copyAll(this->parameters);
02937 return spec;
02938 }
02939
02940 bool CatalogSpec::fromXML(const JString& xml) {
02941
02942 if (xml.length() == 0)
02943 return false;
02944
02945 XMLParser* xmlParser = new XMLParser();
02946 xmlParser->parse(xml);
02947 bool ret = fromXML(xmlParser->getRootNode());
02948 delete(xmlParser);
02949 return ret;
02950 }
02951
02952 bool CatalogSpec::fromXML(XMLNode* node) {
02953
02954 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("Catalog")) )
02955 return false;
02956
02957 Dictionary* attr = node->getAttributes();
02958 if (attr == NULL)
02959 return false;
02960
02961 JString key;
02962 Parameter* parameter;
02963 for (int n=0; n<attr->getCount(); n++) {
02964 key = attr->getKey(n);
02965 if (key.equalsIgnoreCase("name"))
02966 name = attr->get(n);
02967 else if (key.equalsIgnoreCase("remote"))
02968 remote = attr->get(n);
02969 else if (key.equalsIgnoreCase("plug"))
02970 plug = attr->get(n);
02971 else if (key.equalsIgnoreCase("queryhandler"))
02972 queryhandler = attr->get(n);
02973 else if (key.equalsIgnoreCase("category"))
02974 queryhandler = attr->get(n);
02975 else if (key.equalsIgnoreCase("query"))
02976 queryhandler = attr->get(n);
02977 else if (key.length() > 0) {
02978 parameter = new Parameter(key, "String", attr->get(n));
02979 parameters.put(key, parameter);
02980 }
02981 }
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992 XMLNode* xmlNode = node->getChildNode("description");
02993 if (xmlNode == NULL)
02994 description = "";
02995 else
02996 description = xmlNode->getTextContent();
02997
02998 ObjectCollection paramNodes = node->getChildNodes("parameter");
02999 for (XMLNode* paramNode = (XMLNode*) paramNodes.getFirst(); paramNode != NULL; paramNode = (XMLNode*) paramNodes.getNext()) {
03000 parameter = new Parameter(paramNode);
03001 if (parameter->name.length() > 0) {
03002 parameters.put(parameter->name, parameter);
03003 }
03004 else {
03005 delete(parameter);
03006 }
03007 }
03008
03009 return true;
03010 }
03011
03012 JString CatalogSpec::toXML() {
03013 JString xml;
03014
03015 if (description.length() > 0)
03016 xml += JString::format("<description>%s</description>\n", (char*) description.xmlStringEncode());
03017
03018 Parameter* parameter;
03019 for (int n=0; n<parameters.getCount(); n++) {
03020 parameter = (Parameter*) parameters.get(n);
03021 if (parameter != NULL)
03022 xml += JString::format("%s\n", (char*) parameter->toXML());
03023 }
03024
03025 JString attributes;
03026 if (plug.length() > 0)
03027 attributes = JString::format("name=\"%s\" plug=\"%s\"", (char*) name.xmlStringEncode(), (char*) plug.xmlStringEncode());
03028 else if (queryhandler.length() > 0)
03029 attributes = JString::format("name=\"%s\" category=\"%s\"", (char*) name.xmlStringEncode(), (char*) queryhandler.xmlStringEncode());
03030 else
03031 attributes = JString::format("name=\"%s\"", (char*) name.xmlStringEncode());
03032
03033 if (xml.length() > 0) {
03034 return JString::format("<catalog %s remote=\"%s\">\n%s</catalog>", (char*) attributes, (char*) xml.indentXML(), (char*) remote.xmlStringEncode());
03035 }
03036
03037 return JString::format("<catalog %s />", (char*) attributes);
03038 }
03039
03040
03041
03042 JString CatalogSpec::toHTML() {
03043 JString html;
03044 return html;
03045 }
03046
03047
03048
03049
03050
03051
03052
03053
03054
03055
03056
03057
03058 ExecutableSpec::ExecutableSpec() {
03059 consoleOutput = false;
03060 autoRestart = false;
03061 }
03062
03063 ExecutableSpec::ExecutableSpec(const JString& xml) {
03064 consoleOutput = false;
03065 autoRestart = false;
03066 fromXML(xml);
03067 }
03068
03069 ExecutableSpec::ExecutableSpec(XMLNode* node) {
03070 consoleOutput = false;
03071 autoRestart = false;
03072 fromXML(node);
03073 }
03074
03075 ExecutableSpec::~ExecutableSpec() {
03076 }
03077
03078
03079 unsigned long ExecutableSpec::getPayloadSize() const {
03080 return name.getPayloadSize() + startupDir.getPayloadSize() + sysSpecs.getPayloadSize() +
03081 commandLines.getPayloadSize();
03082 }
03083
03084 Object* ExecutableSpec::clone() const {
03085 ExecutableSpec* spec = new ExecutableSpec();
03086 spec->consoleOutput = consoleOutput;
03087 spec->autoRestart = autoRestart;
03088 spec->name = name;
03089 spec->startupDir = startupDir;
03090 spec->sysSpecs.copyAll(sysSpecs);
03091 spec->commandLines.copyAll(commandLines);
03092 return spec;
03093 }
03094
03095 bool ExecutableSpec::fromXML(const JString& xml) {
03096
03097 if (xml.length() == 0)
03098 return false;
03099
03100 XMLParser* xmlParser = new XMLParser();
03101 xmlParser->parse(xml);
03102 bool ret = fromXML(xmlParser->getRootNode());
03103 delete(xmlParser);
03104 return ret;
03105 }
03106
03107 bool ExecutableSpec::fromXML(XMLNode* node) {
03108
03109 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("executable")) )
03110 return false;
03111
03112 name = node->getAttribute("name");
03113 if (node->hasAttribute("consoleoutput"))
03114 consoleOutput = node->getAttribute("consoleoutput").equalsIgnoreCase("yes");
03115 if (node->hasAttribute("autorestart"))
03116 autoRestart = node->getAttribute("autorestart").equalsIgnoreCase("yes");
03117 if (node->hasAttribute("startupdir"))
03118 startupDir = node->getAttribute("startupdir");
03119
03120 JString cmdline;
03121 SysInfo* sysInfo;
03122 JString id;
03123
03124 ObjectCollection sysNodes = node->getChildNodes("sys");
03125 if (sysNodes.getCount() == 0)
03126 sysNodes = node->getChildNodes("command");
03127 if (sysNodes.getCount() == 0) {
03128 if ((cmdline = node->getTextContent()).length() > 0) {
03129 sysInfo = new SysInfo();
03130 sysInfo->clear();
03131 id = createUniqueID();
03132 sysSpecs.put(id, sysInfo);
03133 commandLines.put(id, cmdline);
03134 }
03135 }
03136 else {
03137 for (XMLNode* sysNode = (XMLNode*) sysNodes.getFirst(); sysNode != NULL; sysNode = (XMLNode*) sysNodes.getNext()) {
03138 sysInfo = new SysInfo();
03139 if (sysInfo->fromXML(sysNode)) {
03140 if ((cmdline = sysNode->getTextContent()).length() > 0) {
03141 id = createUniqueID();
03142 sysSpecs.put(id, sysInfo);
03143 commandLines.put(id, cmdline);
03144 }
03145 }
03146 }
03147 }
03148
03149 return true;
03150 }
03151
03152 JString ExecutableSpec::toXML() {
03153 JString xml;
03154
03155 JString cmdline;
03156 SysInfo* sysInfo;
03157 for (JString key = sysSpecs.getFirstKey(); key.length() > 0; key = sysSpecs.getNextKey()) {
03158 if (( (sysInfo = (SysInfo*) sysSpecs.get(key)) != NULL) &&
03159 ( (cmdline = commandLines.get(key)).length() > 0 ) ) {
03160 xml += sysInfo->toXML("command", cmdline);
03161 }
03162 }
03163
03164 return JString::format("<executable name=\"%s\" consoleoutput=\"%s\" autorestart=\"%s\" startupdir=\"%s\">\n%s</executable>",
03165 (char*) name.xmlStringEncode(), (char*) JString(consoleOutput), (char*) JString(autoRestart), (char*) startupDir, (char*) xml.indentXML());
03166 }
03167
03168
03169 JString ExecutableSpec::getMatchingCommandLine() {
03170 SysInfo* sysInfo = new SysInfo();
03171 sysInfo->update();
03172 JString cmdline = getMatchingCommandLine(sysInfo);
03173 delete(sysInfo);
03174 return cmdline;
03175 }
03176
03177 JString ExecutableSpec::getMatchingCommandLine(SysInfo* sysInfo) {
03178
03179 JString cmdline;
03180 SysInfo* storedSysInfo;
03181 for (JString key = sysSpecs.getFirstKey(); key.length() > 0; key = sysSpecs.getNextKey()) {
03182 if (( (storedSysInfo = (SysInfo*) sysSpecs.get(key)) != NULL) &&
03183 ( (storedSysInfo->equals(sysInfo))) &&
03184 ( (cmdline = commandLines.get(key)).length() > 0 ) ) {
03185 return cmdline;
03186 }
03187 }
03188 return "";
03189 }
03190
03191
03192 JString ExecutableSpec::toHTML() {
03193 JString html;
03194 return html;
03195 }
03196
03197
03198
03199
03200
03201
03202
03203
03204
03205
03206
03207
03208 SatelliteSpec::SatelliteSpec() {
03209 }
03210
03211 SatelliteSpec::SatelliteSpec(const JString& xml) {
03212 port = 0;
03213 fromXML(xml);
03214 }
03215
03216 SatelliteSpec::SatelliteSpec(XMLNode* node) {
03217 port = 0;
03218 fromXML(node);
03219 }
03220
03221 SatelliteSpec::~SatelliteSpec() {
03222 }
03223
03224
03225 unsigned long SatelliteSpec::getPayloadSize() const {
03226 return name.getPayloadSize() + host.getPayloadSize();
03227 }
03228
03229 Object* SatelliteSpec::clone() const {
03230 SatelliteSpec* spec = new SatelliteSpec();
03231 spec->name = this->name;
03232 spec->host = this->host;
03233 spec->port = this->port;
03234 return spec;
03235 }
03236
03237 TCPLocation SatelliteSpec::getTCPLocation() {
03238 return TCPLocation(host, port, name);
03239 }
03240
03241
03242 bool SatelliteSpec::fromXML(const JString& xml) {
03243
03244 if (xml.length() == 0)
03245 return false;
03246
03247 XMLParser* xmlParser = new XMLParser();
03248 xmlParser->parse(xml);
03249 bool ret = fromXML(xmlParser->getRootNode());
03250 delete(xmlParser);
03251 return ret;
03252 }
03253
03254 bool SatelliteSpec::fromXML(XMLNode* node) {
03255
03256 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("Satellite")) )
03257 return false;
03258
03259 name = node->findAttr("name");
03260 host = node->findAttr("host");
03261 if (node->hasAttribute("daemonport"))
03262 port = node->findAttr("daemonport").toInt();
03263 else if (node->hasAttribute("demonport"))
03264 port = node->findAttr("demonport").toInt();
03265 else if (node->hasAttribute("deamonport"))
03266 port = node->findAttr("deamonport").toInt();
03267 else if (node->hasAttribute("port"))
03268 port = node->findAttr("port").toInt();
03269 else
03270 port = 10000;
03271 return true;
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289
03290 }
03291
03292 JString SatelliteSpec::toXML() {
03293
03294
03295
03296
03297
03298
03299
03300
03301
03302
03303
03304
03305
03306
03307
03308 return JString::format("<satellite name=\"%s\" host=\"%s\" port=\"%d\" />", (char*) name.xmlStringEncode(), (char*) host.xmlStringEncode(), port);
03309 }
03310
03311
03312
03313 JString SatelliteSpec::toHTML() {
03314 JString html;
03315 return html;
03316 }
03317
03318
03319
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329 ActionSpec::ActionSpec() {
03330 delay = 0;
03331 object = NULL;
03332 answer = NULL;
03333 }
03334
03335 ActionSpec::ActionSpec(JString name, JString act, JString value, JString target, Object* obj, JString content) {
03336 delay = 0;
03337 this->name = name;
03338 this->act = act;
03339 this->target = target;
03340 this->content = content;
03341 this->value = value;
03342 this->object = obj;
03343 answer = NULL;
03344 }
03345
03346 ActionSpec::ActionSpec(const JString& xml) {
03347 delay = 0;
03348 object = NULL;
03349 answer = NULL;
03350 fromXML(xml);
03351 }
03352
03353 ActionSpec::ActionSpec(XMLNode* node) {
03354 delay = 0;
03355 object = NULL;
03356 answer = NULL;
03357 fromXML(node);
03358 }
03359
03360 ActionSpec::~ActionSpec() {
03361 if (object != NULL)
03362 delete(object);
03363 if (answer != NULL)
03364 delete(answer);
03365 }
03366
03367
03368 unsigned long ActionSpec::getPayloadSize() const {
03369 unsigned long payloadSize =
03370 name.getPayloadSize() + state.getPayloadSize() + target.getPayloadSize() +
03371 act.getPayloadSize() + value.getPayloadSize() + content.getPayloadSize() +
03372 params.getPayloadSize();
03373
03374 if (object != NULL) payloadSize += object->getPayloadSize();
03375 if (answer != NULL) payloadSize += answer->getPayloadSize();
03376
03377 return payloadSize;
03378 }
03379
03380 Object* ActionSpec::clone() const {
03381 ActionSpec* spec = new ActionSpec();
03382 spec->name = this->name;
03383 spec->delay = this->delay;
03384 spec->target = this->target;
03385 spec->act = this->act;
03386 spec->value = this->value;
03387 spec->content = this->content;
03388 spec->state = this->state;
03389 if (object != NULL)
03390 spec->object = this->object->clone();
03391 if (answer != NULL)
03392 spec->answer = this->answer->clone();
03393 spec->params.copyAll(this->params);
03394 return spec;
03395 }
03396
03397 bool ActionSpec::setParameter(JString name, JString value) {
03398 return params.put(name, value);
03399 }
03400
03401 JString ActionSpec::getParameter(JString name) {
03402 return params.get(name);
03403 }
03404
03405 bool ActionSpec::fromXML(const JString& xml) {
03406
03407 if (xml.length() == 0)
03408 return false;
03409
03410 XMLParser* xmlParser = new XMLParser();
03411 xmlParser->parse(xml);
03412 bool ret = fromXML(xmlParser->getRootNode());
03413 delete(xmlParser);
03414 return ret;
03415 }
03416
03417 bool ActionSpec::fromXML(XMLNode* node) {
03418
03419 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("action")) )
03420 return false;
03421
03422 name = node->findAttr("name");
03423 delay = node->findAttr("delay").toInt();
03424 target = node->findAttr("target");
03425 act = node->findAttr("act");
03426 content = node->findAttr("content");
03427 value = node->findAttr("value");
03428 state = node->findAttr("state");
03429
03430 XMLNode* answerNode;
03431 ObjectCollection* children = node->getChildTags();
03432 if (children != NULL) {
03433 for (XMLNode* xmlNode = (XMLNode*) children->getFirst(); xmlNode != NULL; xmlNode = (XMLNode*) children->getNext()) {
03434 if (xmlNode->getTag().equalsIgnoreCase("dictionary")) {
03435 params.fromXML(xmlNode);
03436 }
03437 else if (xmlNode->getTag().equalsIgnoreCase("content"))
03438 content = xmlNode->getTextContent();
03439 else if (xmlNode->getTag().equalsIgnoreCase("answer")) {
03440 if ( (answerNode = (XMLNode*)xmlNode->getFirstChildNode()) != NULL) {
03441 if (answer != NULL)
03442 delete(answer);
03443 answer = createObjectFromXML(answerNode);
03444 }
03445 }
03446 else {
03447 if (object != NULL)
03448 delete(object);
03449 object = createObjectFromXML(xmlNode);
03450 }
03451 }
03452 }
03453 return true;
03454 }
03455
03456 JString ActionSpec::toXML() {
03457
03458 JString paramsXML;
03459 if (params.getCount() > 0) {
03460 paramsXML = params.toXML().indentXML();
03461 }
03462
03463 if ( (content.length() == 0) && (object == NULL) && (paramsXML.length() == 0) )
03464 return JString::format("<action name=\"%s\" delay=\"%d\" state=\"%s\" target=\"%s\" act=\"%s\" value=\"%s\" />",
03465 (char*) name.xmlStringEncode(), delay, (char*) state.xmlStringEncode(), (char*) target.xmlStringEncode(), (char*) act.xmlStringEncode(), (char*) value.xmlStringEncode());
03466 else {
03467 JString contentXML;
03468 if (content.length() > 0) {
03469 if (content.looksLikeXML())
03470 contentXML = JString::format("<content>\n%s</content>", (char*) content.indentXML()).indentXML();
03471 else
03472 contentXML = JString::format("\t<content>%s</content>", (char*) content.xmlStringEncode());
03473 }
03474 JString objectXML;
03475 if (object != NULL)
03476 objectXML = object->toXML().indentXML();
03477 JString answerXML;
03478 if (answer != NULL) {
03479 answerXML = JString::format("<answer>\n%s</answer>", (char*) answer->toXML().indentXML()).indentXML();
03480 }
03481
03482 return JString::format("<action name=\"%s\" delay=\"%d\" state=\"%s\" target=\"%s\" act=\"%s\" value=\"%s\">\n%s%s%s%s</action>",
03483 (char*) name.xmlStringEncode(), delay, (char*) state.xmlStringEncode(), (char*) target.xmlStringEncode(), (char*) act.xmlStringEncode(), (char*) value.xmlStringEncode(),
03484 (char*) paramsXML, (char*) contentXML, (char*) objectXML, (char*) answerXML);
03485 }
03486 }
03487
03488 JString ActionSpec::toHTML() {
03489 JString html;
03490 return html;
03491 }
03492
03493
03494
03495
03496
03497
03498
03499 long ActionSpec::getBinarySize(int chunk) {
03500 int chunkCountObject = 0, chunkCountAnswer = 0;
03501 long binarySize = 0;
03502 if (object != NULL) {
03503 chunkCountObject = object->getBinaryChunkCount();
03504 if (chunk <= chunkCountObject)
03505 return object->getBinarySize(chunk);
03506 }
03507 if (answer != NULL) {
03508 chunkCountAnswer = answer->getBinaryChunkCount();
03509 if (chunk > chunkCountObject)
03510 return answer->getBinarySize(chunk - chunkCountObject);
03511 }
03512 return 0;
03513 }
03514
03515
03516 int ActionSpec::getBinaryChunkCount() {
03517 int chunkCountObject = 0, chunkCountAnswer = 0;
03518 if (object != NULL)
03519 chunkCountObject = object->getBinaryChunkCount();
03520 if (answer != NULL)
03521 chunkCountAnswer = answer->getBinaryChunkCount();
03522 return chunkCountObject + chunkCountAnswer;
03523 }
03524
03525
03526 long ActionSpec::toBinaryBuffer(int chunk, char* buffer, int maxlen) {
03527 int chunkCountObject = 0, chunkCountAnswer = 0;
03528 long binarySize = 0;
03529 if (object != NULL) {
03530 chunkCountObject = object->getBinaryChunkCount();
03531 if (chunk <= chunkCountObject)
03532 return object->toBinaryBuffer(chunk, buffer, maxlen);
03533 }
03534 if (answer != NULL) {
03535 chunkCountAnswer = answer->getBinaryChunkCount();
03536 if (chunk > chunkCountObject)
03537 return answer->toBinaryBuffer(chunk-chunkCountObject, buffer, maxlen);
03538 }
03539 return 0;
03540 }
03541
03542
03543 bool ActionSpec::fromBinaryBuffer(int chunk, char* buffer, long len) {
03544 int chunkCountObject = 0, chunkCountAnswer = 0;
03545 long binarySize = 0;
03546 if (object != NULL) {
03547 chunkCountObject = object->getBinaryChunkCount();
03548 if (chunk <= chunkCountObject)
03549 return object->fromBinaryBuffer(chunk, buffer, len);
03550 }
03551 if (answer != NULL) {
03552 chunkCountAnswer = answer->getBinaryChunkCount();
03553 if (chunk > chunkCountObject)
03554 return answer->fromBinaryBuffer(chunk-chunkCountObject, buffer, len);
03555 }
03556 return 0;
03557 }
03558
03559
03560
03561
03562
03563
03564
03565
03566
03567
03568
03569
03570
03571
03572
03573
03574
03575
03576 ClientProfile::ClientProfile() {
03577 }
03578
03579 ClientProfile::ClientProfile(const JString& xml) {
03580 fromXML(xml);
03581 }
03582
03583 ClientProfile::ClientProfile(XMLNode* node) {
03584 fromXML(node);
03585 }
03586
03587 ClientProfile::~ClientProfile() {
03588 }
03589
03590
03591 unsigned long ClientProfile::getPayloadSize() const {
03592 return name.getPayloadSize() + capabilities.getPayloadSize() + connectionProfile.getPayloadSize() +
03593 thisConvID.getPayloadSize() + lastConvID.getPayloadSize();
03594 }
03595
03596 Object* ClientProfile::clone() const {
03597 ClientProfile* spec = new ClientProfile();
03598 spec->name = this->name;
03599 spec->lastConvID = this->lastConvID;
03600 spec->connectionProfile = this->connectionProfile;
03601 spec->capabilities.copyAll(this->capabilities);
03602 return spec;
03603 }
03604
03605 bool ClientProfile::equals(const Object* otherProfile) const {
03606 JString othername = ((ClientProfile*) otherProfile)->name;
03607 return name.equals(othername);
03608 }
03609
03610 bool ClientProfile::fromXML(const JString& xml) {
03611
03612 if (xml.length() == 0)
03613 return false;
03614
03615 XMLParser* xmlParser = new XMLParser();
03616 xmlParser->parse(xml);
03617 bool ret = fromXML(xmlParser->getRootNode());
03618 delete(xmlParser);
03619 return ret;
03620 }
03621
03622 bool ClientProfile::fromXML(XMLNode* node) {
03623
03624 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("clientprofile")) )
03625 return false;
03626
03627 name = node->findAttr("name");
03628 lastConvID = node->findAttr("lastConvID");
03629 thisConvID = node->findAttr("thisConvID");
03630
03631 XMLNode* xmlNode = node->getChildNode("objectdictionary");
03632 if (xmlNode != NULL) {
03633 capabilities.removeAll();
03634 capabilities.fromXML(xmlNode);
03635 }
03636
03637 xmlNode = node->getChildNode("connectionprofile");
03638 if (xmlNode != NULL) {
03639 connectionProfile = ConnectionProfile(xmlNode);
03640 }
03641
03642 return true;
03643 }
03644
03645 JString ClientProfile::toXML() {
03646 return JString::format(
03647 "<clientprofile name=\"%s\" lastConvID=\"%s\" thisConvID=\"%s\">\n%s%s</clientprofile>",
03648 (char*) name.xmlStringEncode(), (char*) lastConvID.xmlStringEncode(), (char*) thisConvID.xmlStringEncode(),
03649 (char*) capabilities.toXML().indentXML(),
03650 (char*) connectionProfile.toXML().indentXML());
03651 }
03652
03653 JString ClientProfile::toHTML() {
03654 return JString::format(
03655 "ClientProfile %s: ConvID=\"%s\"<br>\nCapabilities:<br>%s<br>\n%s<br>\n",
03656 (char*) name.toHTML(), (char*) thisConvID.toHTML(),
03657 (char*) capabilities.toHTML(), (char*) connectionProfile.toHTML());
03658 }
03659
03660 JString ClientProfile::print() {
03661 return JString::format(
03662 "ClientProfile %s: ConvID=\"%s\"\n%s\n%s\n",
03663 (char*) name, (char*) thisConvID,
03664 (char*) capabilities.print(), (char*) connectionProfile.print());
03665 }
03666
03667 JString ClientProfile::getCapability(const JString& category, const JString& capability) {
03668 Dictionary* dict = (Dictionary*) capabilities.get(category.toLowerCase());
03669 if (dict != NULL)
03670 return dict->get(capability.toLowerCase());
03671 else
03672 return "";
03673 }
03674
03675 bool ClientProfile::setCapability(const JString& category, const JString& capability, const JString& value) {
03676 Dictionary* dict = (Dictionary*) capabilities.get(category.toLowerCase());
03677 if (dict == NULL) {
03678 dict = new Dictionary();
03679 capabilities.put(category.toLowerCase(), dict);
03680 }
03681 return dict->put(capability.toLowerCase(), value);
03682 }
03683
03684 bool ClientProfile::hasCapability(const JString& category, const JString& capability) {
03685 Dictionary* dict = (Dictionary*) capabilities.get(category.toLowerCase());
03686 if (dict != NULL)
03687 return dict->contains(capability.toLowerCase());
03688 else
03689 return false;
03690 }
03691
03692
03693
03694
03695
03696
03697
03698
03699
03700
03701
03702
03703
03704
03705 ServiceSpec::ServiceSpec() {
03706 priority = 0;
03707 maxConv = 0;
03708 timeout = 30000;
03709 moduleSpec = new ModuleSpec();
03710 moduleSpec->type = "service";
03711 }
03712
03713 ServiceSpec::ServiceSpec(const JString& xml) {
03714 priority = 0;
03715 maxConv = 0;
03716 timeout = 30000;
03717 moduleSpec = new ModuleSpec();
03718 fromXML(xml);
03719 moduleSpec->type = "service";
03720 }
03721
03722 ServiceSpec::ServiceSpec(XMLNode* node) {
03723 priority = 0;
03724 maxConv = 0;
03725 timeout = 30000;
03726 moduleSpec = new ModuleSpec();
03727 fromXML(node);
03728 }
03729
03730 ServiceSpec::~ServiceSpec() {
03731 delete(moduleSpec);
03732 }
03733
03734
03735 unsigned long ServiceSpec::getPayloadSize() const {
03736 unsigned long payloadSize = name.getPayloadSize() + service.getPayloadSize() + type.getPayloadSize() +
03737 remote.getPayloadSize() + provider.getPayloadSize() + location.getPayloadSize();
03738
03739 if (moduleSpec != NULL) payloadSize += moduleSpec->getPayloadSize();
03740
03741 return payloadSize;
03742 }
03743
03744 Object* ServiceSpec::clone() const {
03745 ServiceSpec* spec = new ServiceSpec();
03746
03747 spec->name = this->name;
03748 spec->service = this->service;
03749 spec->type = this->type;
03750 spec->remote = this->remote;
03751 spec->maxConv = this->maxConv;
03752 spec->timeout = this->timeout;
03753 spec->provider = this->provider;
03754 spec->location = this->location;
03755 spec->priority = this->priority;
03756 delete(spec->moduleSpec);
03757 spec->moduleSpec = (ModuleSpec*) moduleSpec->clone();
03758 return spec;
03759 }
03760
03761 bool ServiceSpec::fromXML(const JString& xml) {
03762
03763 if (xml.length() == 0)
03764 return false;
03765
03766 XMLParser* xmlParser = new XMLParser();
03767 xmlParser->parse(xml);
03768 bool ret = fromXML(xmlParser->getRootNode());
03769 delete(xmlParser);
03770 return ret;
03771 }
03772
03773 bool ServiceSpec::fromXML(XMLNode* node) {
03774
03775 if ( (node == NULL) || (!node->getTag().equalsIgnoreCase("serviceprovider")) )
03776 return false;
03777
03778 name = node->findAttr("name");
03779 service = node->findAttr("service");
03780 type = node->findAttr("type");
03781 if (node->hasAttribute("remote"))
03782 remote = node->findAttr("remote");
03783 else
03784 remote = node->findAttr("satellite");
03785 if (node->hasAttribute("max"))
03786 maxConv = node->findAttr("max").toInt();
03787 else
03788 maxConv = 0;
03789 if (node->hasAttribute("timeout"))
03790 timeout = node->findAttr("timeout").toInt();
03791 else
03792 timeout = 30000;
03793 provider = node->findAttr("provider");
03794
03795
03796 if (node->hasAttribute("priority"))
03797 priority = node->findAttr("priority").toDouble();
03798
03799 XMLNode* xmlNode = node->getChildNode("tcplocation");
03800 if (xmlNode != NULL)
03801 location.fromXML(xmlNode);
03802
03803
03804
03805
03806
03807
03808
03809
03810
03811 if (!moduleSpec->fromXML(node)) {
03812 return false;
03813 }
03814
03815 return true;
03816 }
03817
03818 JString ServiceSpec::toXML() {
03819
03820 JString xml, subxml;
03821
03822 if (location.isValid()) {
03823 xml += location.toXML();
03824 }
03825
03826 if (moduleSpec->description.length() > 0)
03827 xml += JString::format("<description>%s</description>\n", (char*) moduleSpec->description.xmlStringEncode());
03828
03829 if (moduleSpec->allowSelfTriggering)
03830 xml += JString::format("<allowselftriggering>Yes</allowselftriggering>\n");
03831
03832 int n = 0;
03833 Parameter* parameter;
03834 for (n=0; n<moduleSpec->parameters->getCount(); n++) {
03835 parameter = (Parameter*) moduleSpec->parameters->get(n);
03836 if (parameter != NULL)
03837 xml += JString::format("%s\n", (char*) parameter->toXML());
03838
03839 }
03840
03841
03842
03843
03844
03845 subxml = "";
03846 ContextSpec* contextSpec;
03847 for (n=0; n<moduleSpec->contexts->getCount(); n++) {
03848 contextSpec = (ContextSpec*) moduleSpec->contexts->get(n);
03849 if (contextSpec != NULL) {
03850 subxml += contextSpec->toXML() + "\n";
03851 }
03852 }
03853
03854 xml += JString::format("<spec>\n%s</spec>\n", (char*) subxml.indentXML());
03855
03856 if (moduleSpec->configXML.length() > 0) {
03857 xml += JString::format("\n<config>\n%s</config>", (char*) moduleSpec->configXML.indentXML());
03858 }
03859
03860 if (xml.length() > 0) {
03861 return JString::format(
03862 "<serviceprovider name=\"%s\" service=\"%s\" type=\"%s\" max=\"%d\" verbose=\"%d\" provider=\"%s\" timeout=\"%d\" satellite=\"%s\" priority=\"%f\">\n%s</serviceprovider>",
03863 (char*) name.xmlStringEncode(), (char*) service.xmlStringEncode(), (char*) type.xmlStringEncode(), maxConv, moduleSpec->verbose, (char*) provider.xmlStringEncode(),
03864 timeout, (char*) remote.xmlStringEncode(), priority, (char*) xml.indentXML());
03865 }
03866 else {
03867 return JString::format(
03868 "<serviceprovider name=\"%s\" service=\"%s\" type=\"%s\" max=\"%d\" verbose=\"%d\" provider=\"%s\" timeout=\"%d\" satellite=\"%s\" priority=\"%f\" />",
03869 (char*) name.xmlStringEncode(), (char*) service.xmlStringEncode(), (char*) type.xmlStringEncode(), maxConv, moduleSpec->verbose, (char*) provider.xmlStringEncode(),
03870 timeout, (char*) remote.xmlStringEncode(), priority);
03871 }
03872 }
03873
03874 JString ServiceSpec::toHTML() {
03875 JString html;
03876 return html;
03877 }
03878
03879
03880
03881
03882
03883
03884
03885 long ServiceSpec::getBinarySize(int chunk) {
03886 if (moduleSpec == NULL)
03887 return 0;
03888 return moduleSpec->getBinarySize(chunk);
03889 }
03890
03891
03892 int ServiceSpec::getBinaryChunkCount() {
03893 if (moduleSpec == NULL)
03894 return 0;
03895 return moduleSpec->getBinaryChunkCount();
03896 }
03897
03898
03899 long ServiceSpec::toBinaryBuffer(int chunk, char* buffer, int maxlen) {
03900 if (moduleSpec == NULL)
03901 return false;
03902 return moduleSpec->toBinaryBuffer(chunk, buffer, maxlen);
03903 }
03904
03905
03906 bool ServiceSpec::fromBinaryBuffer(int chunk, char* buffer, long len) {
03907 if (moduleSpec == NULL)
03908 return false;
03909 return moduleSpec->fromBinaryBuffer(chunk, buffer, len);
03910 }
03911
03912
03913
03914
03915
03916
03917
03918
03919
03920
03921
03922
03923
03924
03925
03926
03927 }