Skip to content

Commit d2c4c40

Browse files
committed
change state and event enum
Signed-off-by: Emelia Lei <[email protected]>
1 parent b8f4f7e commit d2c4c40

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

src/groups/mqb/mqbnet/mqbnet_initialconnectioncontext.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,16 @@ int InitialConnectionContext::processBlob(bsl::ostream& errorDescription,
291291
}
292292
else if (bsl::holds_alternative<bmqp_ctrlmsg::AuthenticationMessage>(
293293
message)) {
294-
handleEvent(rc, bsl::string(), Event::e_AUTHN_REQUEST, message);
294+
handleEvent(rc,
295+
bsl::string(),
296+
InitialConnectionEvent::e_AUTHN_REQUEST,
297+
message);
295298
}
296299
else {
297-
handleEvent(rc, bsl::string(), Event::e_NEGOTIATION_MESSAGE, message);
300+
handleEvent(rc,
301+
bsl::string(),
302+
InitialConnectionEvent::e_NEGOTIATION_MESSAGE,
303+
message);
298304
}
299305

300306
return rc_SUCCESS;
@@ -468,15 +474,17 @@ void InitialConnectionContext::readCallback(const bmqio::Status& status,
468474

469475
if (!status) {
470476
errStream << "Read error: " << status;
471-
handleEvent(rc_READ_BLOB_ERROR, errStream.str(), Event::e_ERROR);
477+
handleEvent(rc_READ_BLOB_ERROR,
478+
errStream.str(),
479+
InitialConnectionEvent::e_ERROR);
472480
return; // RETURN
473481
}
474482

475483
rc = readBlob(errStream, &outPacket, &isFullBlob, numNeeded, blob);
476484
if (rc != rc_SUCCESS) {
477485
handleEvent((rc * 10) + rc_READ_BLOB_ERROR,
478486
errStream.str(),
479-
Event::e_ERROR);
487+
InitialConnectionEvent::e_ERROR);
480488
return; // RETURN
481489
}
482490

@@ -488,7 +496,7 @@ void InitialConnectionContext::readCallback(const bmqio::Status& status,
488496
if (rc != rc_SUCCESS) {
489497
handleEvent((rc * 10) + rc_PROCESS_BLOB_ERROR,
490498
errStream.str(),
491-
Event::e_ERROR);
499+
InitialConnectionEvent::e_ERROR);
492500
return; // RETURN
493501
}
494502
}
@@ -530,23 +538,21 @@ void InitialConnectionContext::handleInitialConnection()
530538
// `negotiateOutbound`.
531539
handleEvent(0,
532540
bsl::string(),
533-
mqbnet::InitialConnectionEvent::e_OUTBOUND_NEGOTATION);
541+
InitialConnectionEvent::e_OUTBOUND_NEGOTATION);
534542
}
535543
else {
536544
bmqu::MemOutStream errStream;
537545
const int rc = scheduleRead(errStream);
538546
if (rc != 0) {
539-
handleEvent(rc,
540-
errStream.str(),
541-
mqbnet::InitialConnectionEvent::e_ERROR);
547+
handleEvent(rc, errStream.str(), InitialConnectionEvent::e_ERROR);
542548
}
543549
}
544550
}
545551

546552
void InitialConnectionContext::handleEvent(
547553
int statusCode,
548554
const bsl::string& errorDescription,
549-
Event input,
555+
InitialConnectionEvent::Enum input,
550556
const bsl::variant<bsl::monostate,
551557
bmqp_ctrlmsg::AuthenticationMessage,
552558
bmqp_ctrlmsg::NegotiationMessage>& message)
@@ -571,12 +577,12 @@ void InitialConnectionContext::handleEvent(
571577
<< "; peerUri = " << d_channelSp->peerUri()
572578
<< "; context address = " << this;
573579

574-
State oldState = d_state;
580+
InitialConnectionState::Enum oldState = d_state;
575581

576582
switch (input) {
577-
case Event::e_OUTBOUND_NEGOTATION: {
578-
if (oldState == State::e_INITIAL) {
579-
setState(State::e_NEGOTIATING_OUTBOUND);
583+
case InitialConnectionEvent::e_OUTBOUND_NEGOTATION: {
584+
if (oldState == InitialConnectionState::e_INITIAL) {
585+
setState(InitialConnectionState::e_NEGOTIATING_OUTBOUND);
580586

581587
createNegotiationContext();
582588

@@ -591,7 +597,7 @@ void InitialConnectionContext::handleEvent(
591597
}
592598
break;
593599
}
594-
case Event::e_AUTHN_REQUEST: {
600+
case InitialConnectionEvent::e_AUTHN_REQUEST: {
595601
if (!bsl::holds_alternative<bmqp_ctrlmsg::AuthenticationMessage>(
596602
message)) {
597603
errStream << "Expecting AuthenticationMessage for event " << input
@@ -601,8 +607,8 @@ void InitialConnectionContext::handleEvent(
601607
const bmqp_ctrlmsg::AuthenticationMessage& authenticationMsg =
602608
bsl::get<bmqp_ctrlmsg::AuthenticationMessage>(message);
603609

604-
if (oldState == State::e_INITIAL) {
605-
setState(State::e_AUTHENTICATING);
610+
if (oldState == InitialConnectionState::e_INITIAL) {
611+
setState(InitialConnectionState::e_AUTHENTICATING);
606612

607613
rc = d_authenticator_p->handleAuthentication(errStream,
608614
self,
@@ -614,7 +620,7 @@ void InitialConnectionContext::handleEvent(
614620
}
615621
break;
616622
}
617-
case Event::e_NEGOTIATION_MESSAGE: {
623+
case InitialConnectionEvent::e_NEGOTIATION_MESSAGE: {
618624
if (!bsl::holds_alternative<bmqp_ctrlmsg::NegotiationMessage>(
619625
message)) {
620626
errStream << "Expecting NegotiationMessage for event " << input
@@ -624,27 +630,27 @@ void InitialConnectionContext::handleEvent(
624630
const bmqp_ctrlmsg::NegotiationMessage& negotiationMsg =
625631
bsl::get<bmqp_ctrlmsg::NegotiationMessage>(message);
626632

627-
if (oldState == State::e_INITIAL &&
633+
if (oldState == InitialConnectionState::e_INITIAL &&
628634
negotiationMsg.isClientIdentityValue()) {
629-
setState(State::e_ANON_AUTHENTICATING);
635+
setState(InitialConnectionState::e_ANON_AUTHENTICATING);
630636

631637
createNegotiationContext();
632638
negotiationContext()->setNegotiationMessage(negotiationMsg);
633639

634640
rc = handleAnonAuthentication(errStream);
635641
}
636-
else if (oldState == State::e_AUTHENTICATED &&
642+
else if (oldState == InitialConnectionState::e_AUTHENTICATED &&
637643
negotiationMsg.isClientIdentityValue()) {
638-
setState(State::e_NEGOTIATED);
644+
setState(InitialConnectionState::e_NEGOTIATED);
639645

640646
createNegotiationContext();
641647
negotiationContext()->setNegotiationMessage(negotiationMsg);
642648

643649
rc = rc_SUCCESS;
644650
}
645-
else if (oldState == State::e_NEGOTIATING_OUTBOUND &&
651+
else if (oldState == InitialConnectionState::e_NEGOTIATING_OUTBOUND &&
646652
negotiationMsg.isBrokerResponseValue()) {
647-
setState(State::e_NEGOTIATED);
653+
setState(InitialConnectionState::e_NEGOTIATED);
648654

649655
BSLS_ASSERT_SAFE(negotiationContext());
650656
negotiationContext()->setNegotiationMessage(negotiationMsg);
@@ -658,15 +664,15 @@ void InitialConnectionContext::handleEvent(
658664
}
659665
break;
660666
}
661-
case Event::e_AUTHN_SUCCESS: {
662-
if (oldState == State::e_AUTHENTICATING) {
663-
setState(State::e_AUTHENTICATED);
667+
case InitialConnectionEvent::e_AUTHN_SUCCESS: {
668+
if (oldState == InitialConnectionState::e_AUTHENTICATING) {
669+
setState(InitialConnectionState::e_AUTHENTICATED);
664670

665671
// Now read Negotiation message
666672
rc = scheduleRead(errStream);
667673
}
668-
else if (oldState == State::e_ANON_AUTHENTICATING) {
669-
setState(State::e_NEGOTIATED);
674+
else if (oldState == InitialConnectionState::e_ANON_AUTHENTICATING) {
675+
setState(InitialConnectionState::e_NEGOTIATED);
670676

671677
BSLS_ASSERT_SAFE(negotiationContext());
672678
BSLS_ASSERT_SAFE(negotiationContext()
@@ -681,11 +687,11 @@ void InitialConnectionContext::handleEvent(
681687
}
682688
break;
683689
}
684-
case Event::e_ERROR: {
690+
case InitialConnectionEvent::e_ERROR: {
685691
rc = statusCode;
686692
errStream << errorDescription;
687693
} break;
688-
case Event::e_NONE: {
694+
case InitialConnectionEvent::e_NONE: {
689695
// NOT IMPLEMENTED
690696
BSLS_ASSERT_SAFE(!"Unexpected event received: " + input);
691697
break;
@@ -700,12 +706,12 @@ void InitialConnectionContext::handleEvent(
700706

701707
bsl::shared_ptr<mqbnet::Session> session;
702708

703-
if (rc == rc_SUCCESS && d_state == State::e_NEGOTIATED) {
709+
if (rc == rc_SUCCESS && d_state == InitialConnectionState::e_NEGOTIATED) {
704710
rc = d_negotiator_p->createSessionOnMsgType(errStream, &session, this);
705711
BALL_LOG_INFO << "Created a session with " << channel()->peerUri();
706712
}
707713

708-
if (rc != rc_SUCCESS || d_state == State::e_NEGOTIATED) {
714+
if (rc != rc_SUCCESS || d_state == InitialConnectionState::e_NEGOTIATED) {
709715
BALL_LOG_INFO << "Finished initial connection with rc = " << rc
710716
<< ", error = '" << errStream.str() << "'";
711717
guard.release()->unlock();

src/groups/mqb/mqbnet/mqbnet_initialconnectioncontext.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ class InitialConnectionContext
216216
const InitialConnectionContext* initialConnectionContext)>
217217
InitialConnectionCompleteCb;
218218

219-
typedef mqbnet::InitialConnectionState::Enum State;
220-
typedef mqbnet::InitialConnectionEvent::Enum Event;
221-
222219
private:
223220
// DATA
224221

@@ -289,7 +286,7 @@ class InitialConnectionContext
289286
bmqp::EncodingType::Enum d_authenticationEncodingType;
290287

291288
/// The state of the initial connection.
292-
State d_state;
289+
InitialConnectionState::Enum d_state;
293290

294291
/// True if the session being negotiated originates from a remote peer
295292
/// (i.e., a 'listen'); false if it originates from us (i.e., a 'connect').
@@ -328,7 +325,7 @@ class InitialConnectionContext
328325

329326
private:
330327
// PRIVATE MANIPULATORS
331-
void setState(State value);
328+
void setState(InitialConnectionState::Enum value);
332329

333330
int readBlob(bsl::ostream& errorDescription,
334331
bdlbb::Blob* outPacket,
@@ -391,9 +388,9 @@ class InitialConnectionContext
391388
/// `errorDescription` and drive the authentication/negotiation state
392389
/// machine. The `message` optionally contains any associated
393390
/// authentication/negotiation message data.
394-
void handleEvent(int statusCode,
395-
const bsl::string& errorDescription,
396-
Event input,
391+
void handleEvent(int statusCode,
392+
const bsl::string& errorDescription,
393+
InitialConnectionEvent::Enum input,
397394
const bsl::variant<bsl::monostate,
398395
bmqp_ctrlmsg::AuthenticationMessage,
399396
bmqp_ctrlmsg::NegotiationMessage>&
@@ -411,7 +408,7 @@ class InitialConnectionContext
411408
authenticationContext() const;
412409
const bsl::shared_ptr<NegotiationContext>& negotiationContext() const;
413410
bool isClosed() const;
414-
State state() const;
411+
InitialConnectionState::Enum state() const;
415412

416413
/// Invoke the `initialConnectionCompleteCb` callback with the specified
417414
/// return code `rc`, `error` description, and `session` (negotiated

0 commit comments

Comments
 (0)