Created
June 25, 2012 12:20
-
-
Save scymtym/2988271 to your computer and use it in GitHub Desktop.
PortConfiguration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: PortConfiguration.cpp | |
=================================================================== | |
--- PortConfiguration.cpp (revision 488) | |
+++ PortConfiguration.cpp (working copy) | |
@@ -10,6 +10,8 @@ | |
#include <rsb/Informer.h> | |
#include <rsb/Listener.h> | |
+#include <rsb/transport/transports.h> | |
+ | |
#include "cca/Config.h" | |
using namespace std; | |
@@ -69,24 +71,51 @@ | |
} | |
PortConfiguration::PortConfiguration(const std::string &scp, bool loc, bool rem, | |
- unsigned int qsize, bool keepl) : | |
- local(loc), remote(rem), keeplatest(keepl), scope(new Scope(scp)), rsbconfig(), queuesize( | |
- qsize) { | |
+ unsigned int qsize, bool keepl) : | |
+ local(loc), remote(rem), keeplatest(keepl), scope(new Scope(scp)), | |
+ queuesize(qsize) { | |
// Participant configuration | |
this->rsbconfig = Factory::getInstance().getDefaultParticipantConfig(); | |
+ set<ParticipantConfig::Transport> transports | |
+ = this->rsbconfig.getTransports(); | |
+ | |
// Local Transport Configuration | |
- ParticipantConfig::Transport inp_transp = this->rsbconfig.mutableTransport( | |
- "inprocess"); | |
- inp_transp.setEnabled(local); | |
- this->rsbconfig.addTransport(inp_transp); | |
- // Remote Transport Configuration | |
- ParticipantConfig::Transport spr_transp = this->rsbconfig.mutableTransport( | |
- "spread"); | |
- spr_transp.setEnabled(remote); | |
- this->rsbconfig.addTransport(spr_transp); | |
+ bool localSatisfied = true; // maybe later !this->local; | |
+ bool remoteSatisfied = !this->remote; | |
+ for (set<ParticipantConfig::Transport>::const_iterator it = transports.begin(); | |
+ it != transports.end(); ++it) { | |
+ ParticipantConfig::Transport transport = *it; | |
+ | |
+ // Configure local transport | |
+ if (!rsb::transport::isRemote(transport.getName())) { | |
+ transport.setEnabled(this->local); | |
+ } | |
+ | |
+ // Configure remote transport | |
+ // If the transport is enabled and we want remote transports, | |
+ // just leave it enabled. Otherwise, disable the transport. If | |
+ // we want remote transports, make sure, we found at least one | |
+ // enabled remote transport. | |
+ else { | |
+ if (transport.isEnabled()) { | |
+ if (this->remote) | |
+ remoteSatisfied = true; | |
+ else | |
+ transport.setEnabled(false); | |
+ } | |
+ } | |
+ | |
+ this->rsbconfig.addTransport(transport); | |
+ } | |
+ if (!localSatisfied) { | |
+ throw std::invalid_argument("Local transport, but no local transport is enabled in RSB configuration."); | |
+ } | |
+ if (!remoteSatisfied) { | |
+ throw std::invalid_argument("Remote transport requested, but no remote transport is enabled in RSB configuration."); | |
+ } | |
} | |
PortConfiguration::~PortConfiguration() { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment