NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
io_message.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
27 
28 #include <doca_log.h>
29 
31 
32 DOCA_LOG_REGISTER(IO_MESSAGE);
33 
34 namespace storage {
35 
36 static std::string to_string(storage::io_message_type e)
37 {
38  switch (e) {
40  return "result";
42  return "read";
44  return "write";
45  default:
46  return "unknown(" + std::to_string(static_cast<int>(e)) + ")";
47  }
48 }
49 
50 std::string io_message_to_string(char const *buf)
51 {
52  using namespace std::string_literals;
53  using std::to_string;
54 
55  auto const msg_type = io_message_view::get_type(buf);
56  std::string s = "type: " + to_string(msg_type) +
57  ", user_data: " + to_string(io_message_view::get_user_data(buf).u64) +
58  ", correlation_id: " + to_string(io_message_view::get_correlation_id(buf));
59 
60  switch (msg_type) {
62  s += ", result: "s + doca_error_get_name(io_message_view::get_result(buf));
63  break;
66  s += ", address: " + to_string(io_message_view::get_io_address(buf)) +
67  ", length: " + to_string(io_message_view::get_io_size(buf)) +
68  ", remote_offset: " + to_string(io_message_view::get_remote_offset(buf));
69  break;
70  default:
71  break;
72  }
73 
74  return s;
75 }
76 
77 } /* namespace storage */
static uint32_t get_correlation_id(char const *buf)
Definition: io_message.hpp:114
static uint32_t get_io_size(char const *buf)
Definition: io_message.hpp:187
static doca_data get_user_data(char const *buf)
Definition: io_message.hpp:90
static uint32_t get_remote_offset(char const *buf)
Definition: io_message.hpp:211
static io_message_type get_type(char const *buf)
Definition: io_message.hpp:66
static uint64_t get_io_address(char const *buf)
Definition: io_message.hpp:163
static doca_error_t get_result(char const *buf)
Definition: io_message.hpp:138
DOCA_STABLE const char * doca_error_get_name(doca_error_t error)
Returns the string representation of an error code name.
uint64_t u64
DOCA_LOG_REGISTER(IO_MESSAGE)
std::string io_message_to_string(char const *buf)
Definition: io_message.cpp:50
static std::string to_string(storage::io_message_type e)
Definition: io_message.cpp:36