Initial source commit
[ric-plt/xapp-frame-cpp.git] / src / messaging / message.hpp
diff --git a/src/messaging/message.hpp b/src/messaging/message.hpp
new file mode 100644 (file)
index 0000000..8c06ed1
--- /dev/null
@@ -0,0 +1,106 @@
+// vi: ts=4 sw=4 noet:
+/*
+==================================================================================
+       Copyright (c) 2020 Nokia
+       Copyright (c) 2020 AT&T Intellectual Property.
+
+   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.
+==================================================================================
+*/
+
+/*
+       Mnemonic:       message.hpp
+       Abstract:       Headers for the message class.
+                               This class provides an interface to the user application
+                               when information from the message is needed.
+
+       Date:           10 March 2020
+       Author:         E. Scott Daniels
+*/
+
+#ifndef _MESSAGE_HPP
+#define _MESSAGE_HPP
+
+
+#include <iostream>
+#include <string>
+
+#include <rmr/rmr.h>
+
+#include "msg_component.hpp"
+#include "callback.hpp"
+#include "default_cb.hpp"
+
+#ifndef RMR_NO_CLONE
+       #define RMR_NO_CLONE    0
+       #define RMR_NO_COPY     0
+       #define RMR_CLONE       1
+       #define RMR_COPY        1
+#endif
+
+
+// ------------------------------------------------------------------------
+
+class Message {
+       private:
+               static const int        NOCHANGE = -99; // internal constant indicating no change to something
+
+               rmr_mbuf_t*     mbuf;                                   // the underlying RMR message buffer
+               void*           mrc;                                    // message router context
+               std::shared_ptr<char> psp;                      // shared pointer to the payload to give out
+
+       public:
+               static const int        INVALID_MTYPE = -1;
+               static const int        INVALID_STATUS = -1;
+               static const int        INVALID_SUBID = -2;
+               static const int        NO_SUBID = -1;                                  // not all messages have a subid
+
+               static const int        RESPONSE = 0;                                   // send types
+               static const int        MESSAGE = 1;
+
+               Message( rmr_mbuf_t* mbuf, void* mrc );         // builders
+               Message( void* mrc, int payload_len );
+               ~Message();                                                                     // destroyer
+
+               std::unique_ptr<unsigned char>  Copy_payload( );                // copy the payload; deletable smart pointer
+
+               std::unique_ptr<unsigned char> Get_meid();              // returns a copy of the meid bytes
+               int Get_available_size();
+               int     Get_len();
+               int     Get_mtype();
+               Msg_component Get_payload();
+               std::unique_ptr<unsigned char>  Get_src();
+               int     Get_state( );
+               int     Get_subid();
+
+               void Set_meid( std::unique_ptr<unsigned char> new_meid );
+               void Set_mtype( int new_type );
+               void Set_subid( int new_subid );
+
+               bool Reply( );
+               bool Send( );
+               bool Send( int mtype, int subid, int payload_len, unsigned char* payload, int stype );
+
+               bool Send_msg( int mtype, int subid, int payload_len, std::unique_ptr<unsigned char> payload );
+               bool Send_msg( int mtype, int subid, int payload_len, unsigned char* payload );
+               bool Send_msg( int payload_len, std::unique_ptr<unsigned char> payload );
+               bool Send_msg( int payload_len, unsigned char* payload );
+
+               bool Send_response( int mtype, int subid, int payload_len, std::unique_ptr<unsigned char> response );
+               bool Send_response( int mtype, int subid, int payload_len, unsigned char* response );
+               bool Send_response( int payload_len, std::unique_ptr<unsigned char> response );
+               bool Send_response( int payload_len, unsigned char* response );
+};
+
+
+#endif