NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
sync_event_remote_pci_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 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 
26 #include <stdlib.h>
27 
28 #include <doca_argp.h>
29 #include <doca_log.h>
30 
31 #include "common_common.h"
32 
33 DOCA_LOG_REGISTER(SYNC_EVENT::MAIN);
34 
35 /*
36  * Sample's logic
37  *
38  * @se_cfg [in]: user configuration represents command line arguments
39  * @se_rt_objs [in/out]: sample's runtime resources
40  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
41  */
43 
44 /*
45  * Sample main function
46  *
47  * @argc [in]: command line arguments size
48  * @argv [in]: array of command line arguments
49  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
50  */
51 int main(int argc, char **argv)
52 {
54  struct sync_event_config se_cfg;
55  struct sync_event_runtime_objects se_rt_objs;
56  struct doca_log_backend *sdk_log;
57  int exit_status = EXIT_FAILURE;
58 
59  memset(&se_cfg, 0, sizeof(struct sync_event_config));
60  memset(&se_rt_objs, 0, sizeof(struct sync_event_runtime_objects));
62 
63  /* Register a logger backend */
65  if (result != DOCA_SUCCESS)
66  goto sample_exit;
67 
68  /* Register a logger backend for internal SDK errors and warnings */
70  if (result != DOCA_SUCCESS)
71  goto sample_exit;
73  if (result != DOCA_SUCCESS)
74  goto sample_exit;
75 
76  DOCA_LOG_INFO("Starting the sample");
77 
78  result = doca_argp_init(NULL, &se_cfg);
79  if (result != DOCA_SUCCESS) {
80  DOCA_LOG_ERR("Failed to init argp: %s", doca_error_get_descr(result));
81  goto sample_exit;
82  }
83 
85  if (result != DOCA_SUCCESS) {
86  DOCA_LOG_ERR("Failed to register sample parameters: %s", doca_error_get_descr(result));
87  goto argp_cleanup;
88  }
89 
90  result = doca_argp_start(argc, argv);
91  if (result != DOCA_SUCCESS) {
92  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
93  goto argp_cleanup;
94  }
95 
96  result = sync_event_run(&se_cfg, &se_rt_objs);
97  if (result != DOCA_SUCCESS) {
98  DOCA_LOG_ERR("sync_event_run() encountered an error: %s", doca_error_get_descr(result));
99  goto argp_cleanup;
100  }
101 
102  exit_status = EXIT_SUCCESS;
103 
104 argp_cleanup:
106 sample_exit:
107  if (exit_status == EXIT_SUCCESS)
108  DOCA_LOG_INFO("Sample finished successfully");
109  else
110  DOCA_LOG_INFO("Sample finished with errors");
111  return exit_status;
112 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
doca_error_t sync_event_params_register(void)
DOCA_EXPERIMENTAL doca_error_t doca_argp_start(int argc, char **argv)
Parse incoming arguments (cmd line/json).
DOCA_EXPERIMENTAL doca_error_t doca_argp_init(const char *program_name, void *program_config)
Initialize the parser interface.
DOCA_EXPERIMENTAL doca_error_t doca_argp_destroy(void)
ARG Parser destroy.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_UNKNOWN
Definition: doca_error.h:39
@ DOCA_SUCCESS
Definition: doca_error.h:38
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_standard(void)
Create default, non configurable backend for application messages.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_with_file_sdk(FILE *fptr, struct doca_log_backend **backend)
Create a logging backend with a FILE* stream for SDK messages.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_set_sdk_level(struct doca_log_backend *backend, uint32_t level)
Set the log level limit for SDK logging backends.
@ DOCA_LOG_LEVEL_WARNING
Definition: doca_log.h:47
DOCA_LOG_REGISTER(SYNC_EVENT::MAIN)
int main(int argc, char **argv)
doca_error_t sync_event_run(struct sync_event_config *se_cfg, struct sync_event_runtime_objects *se_rt_objs)