LCOV - code coverage report
Current view: top level - eventdispatcher - message.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2019-08-10 01:48:51 Functions: 2 6 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2012-2019  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/eventdispatcher
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software; you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation; either version 2 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License
      17             : // along with this program; if not, write to the Free Software
      18             : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      19             : #pragma once
      20             : 
      21             : /** \file
      22             :  * \brief Event dispatch class.
      23             :  *
      24             :  * Class used to handle events.
      25             :  */
      26             : 
      27             : // self
      28             : //
      29             : #include    "eventdispatcher/utils.h"
      30             : 
      31             : 
      32             : 
      33             : namespace ed
      34             : {
      35             : 
      36             : 
      37             : 
      38             : typedef int                         message_version_t;
      39             : 
      40             : // this version defines the protocol version, it should really rarely
      41             : // change if ever
      42             : //
      43             : constexpr message_version_t         MESSAGE_VERSION = 1;
      44             : 
      45             : constexpr char const                MESSAGE_VERSION_NAME[]  = "version";
      46             : 
      47             : 
      48             : 
      49           4 : class message
      50             : {
      51             : public:
      52             :     typedef std::vector<message>    vector_t;
      53             :     typedef string_map_t            parameters_t;
      54             : 
      55             :     bool                    from_message(std::string const & msg);
      56             :     std::string             to_message() const;
      57             : 
      58             :     std::string const &     get_sent_from_server() const;
      59             :     void                    set_sent_from_server(std::string const & server);
      60             :     std::string const &     get_sent_from_service() const;
      61             :     void                    set_sent_from_service(std::string const & service);
      62             :     std::string const &     get_server() const;
      63             :     void                    set_server(std::string const & server);
      64             :     std::string const &     get_service() const;
      65             :     void                    set_service(std::string const & service);
      66             :     void                    reply_to(message const & msg);
      67             :     std::string const &     get_command() const;
      68             :     void                    set_command(std::string const & command);
      69             :     message_version_t       get_message_version() const;
      70             :     bool                    check_version_parameter() const;
      71             :     void                    add_version_parameter();
      72             :     void                    add_parameter(std::string const & name, std::string const & value);
      73             :     void                    add_parameter(std::string const & name, std::int32_t value);
      74             :     void                    add_parameter(std::string const & name, std::uint32_t value);
      75             :     void                    add_parameter(std::string const & name, long long value);
      76             :     void                    add_parameter(std::string const & name, unsigned long long value);
      77             :     void                    add_parameter(std::string const & name, std::int64_t value);
      78             :     void                    add_parameter(std::string const & name, std::uint64_t value);
      79             :     bool                    has_parameter(std::string const & name) const;
      80             :     std::string             get_parameter(std::string const & name) const;
      81             :     std::int64_t            get_integer_parameter(std::string const & name) const;
      82             :     parameters_t const &    get_all_parameters() const;
      83             : 
      84             : private:
      85             :     std::string             f_sent_from_server = std::string();
      86             :     std::string             f_sent_from_service = std::string();
      87             :     std::string             f_server = std::string();
      88             :     std::string             f_service = std::string();
      89             :     std::string             f_command = std::string();
      90             :     parameters_t            f_parameters = parameters_t();
      91             :     mutable std::string     f_cached_message = std::string();
      92             : };
      93             : 
      94             : 
      95             : void        verify_message_name(
      96             :                   std::string const & name
      97             :                 , bool can_be_empty = false
      98             :                 , bool can_be_lowercase = true);
      99             : 
     100             : 
     101             : 
     102             : } // namespace snap
     103             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12