@@ -35,7 +35,7 @@ pub struct InfoBuilder {
3535impl InfoBuilder {
3636 pub fn new ( component : & str ) -> InfoBuilder {
3737 InfoBuilder {
38- info : ParticipantInfo { .. Default :: default ( ) }
38+ info : ParticipantInfo { component : component . to_string ( ) , .. Default :: default ( ) }
3939 }
4040 }
4141
@@ -44,6 +44,11 @@ impl InfoBuilder {
4444 self
4545 }
4646
47+ pub fn role ( & mut self , role : & str ) -> & mut InfoBuilder {
48+ self . info . role = role. to_string ( ) ;
49+ self
50+ }
51+
4752 pub fn inport ( & mut self , id : & str ) -> & mut InfoBuilder {
4853 let port = ParticipantPort { id : id. to_string ( ) , queue : "" . to_string ( ) } ;
4954 self . info . inports . push ( port) ;
@@ -206,10 +211,10 @@ impl Default for ParticipantOptions {
206211 }
207212}
208213
209- fn normalize_info ( info : & ParticipantInfo , options : & ParticipantOptions ) -> ParticipantInfo {
214+ fn normalize_info ( old : & ParticipantInfo , options : & ParticipantOptions ) -> ParticipantInfo {
210215 use rand:: { thread_rng, Rng } ;
211216
212- let mut new = info . clone ( ) ;
217+ let mut new = old . clone ( ) ;
213218
214219 // normalize role name
215220 if options. role != "" {
@@ -225,15 +230,22 @@ fn normalize_info(info: &ParticipantInfo, options: &ParticipantOptions) -> Parti
225230 new. id = format ! ( "{}-{}" , new. role, id_rnd) ;
226231
227232 // generate port defaults
228-
229- // FIXME: allow to specify queue explicitly
230- //new.inports =
233+ let role = new. role . to_string ( ) ; // NOTE: would be nice to be able to pass reference to info?
234+ let normalize_port = | o : & ParticipantPort | -> ParticipantPort {
235+ let mut p = o. clone ( ) ;
236+ if p. queue == "" {
237+ p. queue = default_queue ( role. to_string ( ) , p. id . to_string ( ) ) ;
238+ }
239+ return p;
240+ } ;
241+ new. inports = old. inports . iter ( ) . map ( & normalize_port) . collect ( ) ;
242+ new. outports = old. outports . iter ( ) . map ( & normalize_port) . collect ( ) ;
231243
232244 return new;
233245}
234246
235247fn default_queue ( role : String , port_name : String ) -> String {
236- return role + "." + & port_name. to_uppercase ( ) ;
248+ return format ! ( "{}.{}" , role , port_name. to_uppercase( ) ) ;
237249}
238250
239251fn parse ( options : & mut ParticipantOptions ) {
@@ -253,12 +265,13 @@ fn parse(options: &mut ParticipantOptions) {
253265// XXX: seems rust-amqp makes program hangs forever if error occurs / channel is borked?
254266// TODO: pass port info in/out of process()
255267// TODO: nicer way to declare ports? ideally they are enums not stringly typed?
256- pub fn main ( p : Participant ) {
268+ pub fn main ( orig : Participant ) {
257269
258270 let mut options = ParticipantOptions { .. Default :: default ( ) } ;
259271 parse ( & mut options) ;
260272
261- normalize_info ( & p. info , & options) ;
273+ let info = normalize_info ( & orig. info , & options) ;
274+ let p = Participant { info : info, process : orig. process } ; // XXX: hack
262275
263276 let mut c = start_participant ( & p, & options) ;
264277 println ! ( "{}({}) started" , & options. role, & p. info. component) ;
0 commit comments