// Copyright 2014-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // bmqa_sessionevent.h -*-C++-*- #ifndef INCLUDED_BMQA_SESSIONEVENT #define INCLUDED_BMQA_SESSIONEVENT //@PURPOSE: Provide value-semantic type for system event session notifications. // //@CLASSES: // bmqa::SessionEvent: type for notification events related to the 'Session'. // //@SEE_ALSO: // bmqt::SessionEventType: Enum of the various type of notifications // //@DESCRIPTION: This component provides a generic 'bmqa::SessionEvent' // notification object used by the 'bmqa::Session' to provide BlazingMQ // applications with information regarding changes in the session status or the // result of operations with the message queue broker. // // A 'SessionEvent' is composed of 4 attributes: //: o !type!: indicate the type of the notification //: o !statusCode!: indicate the status of the operation (success, //: failure) //: o !correlationId!: optional correlationId used during async response //: o !queueId!: optional queueId associated with the event, of type //: 'OPEN', 'CONFIGURE', 'CLOSE', 'REOPEN' //: o !errorDescription!: optional string with a human readable description of //: the error, if any // // Note that 'SessionEvent' is implemented using the pimpl idiom, so copying a // 'SessionEvent' is very cheap (a pointer copy). All copies of this // 'SessionEvent' will share the same underlying implementation. // BMQ #include <bmqscm_version.h> #include <bmqa_queueid.h> #include <bmqt_correlationid.h> #include <bmqt_sessioneventtype.h> // BDE #include <bsl_memory.h> #include <bsl_string.h> namespace BloombergLP { // FORWARD DECLARATION namespace bmqimp { class Event; } namespace bmqa { // ================== // class SessionEvent // ================== class SessionEvent { // An event related to the operation of a 'Session'. private: // FRIENDS friend bool operator==(const SessionEvent& lhs, const SessionEvent& rhs); friend bool operator!=(const SessionEvent& lhs, const SessionEvent& rhs); private: // DATA bsl::shared_ptr<bmqimp::Event> d_impl_sp; // pimpl public: // CREATORS explicit SessionEvent(); // Default constructor SessionEvent(const SessionEvent& other); // Create a new 'SessionEvent' having the same values (pointing to the // same pimpl) as the specified 'other'. // MANIPULATORS SessionEvent& operator=(const SessionEvent& rhs); // Assign to this 'SessionEvent' the same values as the one from the // specified 'rhs' (i.e., reference the same pimpl). // ACCESSORS bmqt::SessionEventType::Enum type() const; // Return the session event type. const bmqt::CorrelationId& correlationId() const; // Return the correlationId associated to this event, if any. QueueId queueId() const; // Return the queueId associated to this event, if any. The behavior // is undefined unless this event corresponds to a queue related event // (i.e. 'OPEN', 'CONFIGURE', 'CLOSE', 'REOPEN'). int statusCode() const; // Return the status code that indicates success or the cause of a // failure. const bsl::string& errorDescription() const; // Return a printable description of the error, if 'statusCode' returns // non-zero. Return an empty string otherwise. bsl::ostream& print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const; // Format this object to the specified output 'stream' at the (absolute // value of) the optionally specified indentation 'level' and return a // reference to 'stream'. If 'level' is specified, optionally specify // 'spacesPerLevel', the number of spaces per indentation level for // this and all of its nested objects. If 'level' is negative, // suppress indentation of the first line. If 'spacesPerLevel' is // negative format the entire output on one line, suppressing all but // the initial indentation (as governed by 'level'). If 'stream' is // not valid on entry, this operation has no effect. }; // FREE OPERATORS bool operator==(const SessionEvent& lhs, const SessionEvent& rhs); // Return 'true' if the specified 'rhs' object contains the value of the // same type as contained in the specified 'lhs' object and the value // itself is the same in both objects, return false otherwise. bool operator!=(const SessionEvent& lhs, const SessionEvent& rhs); // Return 'false' if the specified 'rhs' object contains the value of the // same type as contained in the specified 'lhs' object and the value // itself is the same in both objects, return 'true' otherwise. bsl::ostream& operator<<(bsl::ostream& stream, const SessionEvent& rhs); // Format the specified 'rhs' to the specified output 'stream' and return a // reference to the modifiable 'stream'. } // close package namespace // ============================================================================ // INLINE DEFINITIONS // ============================================================================ // ------------------ // class SessionEvent // ------------------ inline bsl::ostream& bmqa::operator<<(bsl::ostream& stream, const bmqa::SessionEvent& rhs) { return rhs.print(stream, 0, -1); } } // close enterprise namespace #endif