NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
decompress_deflate_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 #include <string.h>
28 
29 #include <doca_argp.h>
30 #include <doca_compress.h>
31 #include <doca_dev.h>
32 #include <doca_error.h>
33 #include <doca_log.h>
34 
35 #include <utils.h>
36 
37 #include "compress_common.h"
38 
39 DOCA_LOG_REGISTER(DECOMPRESS_DEFLATE::MAIN);
40 
41 /* Sample's Logic */
42 doca_error_t decompress_deflate(struct compress_cfg *cfg, char *file_data, size_t file_size);
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 {
55  char *file_data = NULL;
56  size_t file_size;
57  struct doca_log_backend *sdk_log;
58  int exit_status = EXIT_FAILURE;
59 
60  strcpy(compress_cfg.pci_address, "03:00.0");
61  strcpy(compress_cfg.file_path, "data_to_decompress.txt");
62  strcpy(compress_cfg.output_path, "out.txt");
65 
66  /* Register a logger backend */
68  if (result != DOCA_SUCCESS)
69  goto sample_exit;
70 
71  /* Register a logger backend for internal SDK errors and warnings */
73  if (result != DOCA_SUCCESS)
74  goto sample_exit;
76  if (result != DOCA_SUCCESS)
77  goto sample_exit;
78 
79  DOCA_LOG_INFO("Starting the sample");
80 
82  if (result != DOCA_SUCCESS) {
83  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
84  goto sample_exit;
85  }
86 
88  if (result != DOCA_SUCCESS) {
89  DOCA_LOG_ERR("Failed to register ARGP params: %s", doca_error_get_descr(result));
90  goto argp_cleanup;
91  }
92 
94  if (result != DOCA_SUCCESS) {
95  DOCA_LOG_ERR("Failed to register ARGP params for deflate tasks: %s", doca_error_get_descr(result));
96  goto argp_cleanup;
97  }
98 
99  result = doca_argp_start(argc, argv);
100  if (result != DOCA_SUCCESS) {
101  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
102  goto argp_cleanup;
103  }
104 
105  result = read_file(compress_cfg.file_path, &file_data, &file_size);
106  if (result != DOCA_SUCCESS) {
107  DOCA_LOG_ERR("Failed to read file: %s", doca_error_get_descr(result));
108  goto argp_cleanup;
109  }
110 
111  result = decompress_deflate(&compress_cfg, file_data, file_size);
112  if (result != DOCA_SUCCESS) {
113  DOCA_LOG_ERR("decompress_deflate() encountered an error: %s", doca_error_get_descr(result));
114  goto data_file_cleanup;
115  }
116 
117  exit_status = EXIT_SUCCESS;
118 
119 data_file_cleanup:
120  if (file_data != NULL)
121  free(file_data);
122 argp_cleanup:
124 sample_exit:
125  if (exit_status == EXIT_SUCCESS)
126  DOCA_LOG_INFO("Sample finished successfully");
127  else
128  DOCA_LOG_INFO("Sample finished with errors");
129  return exit_status;
130 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
doca_error_t register_compress_params(void)
doca_error_t register_deflate_params(void)
int main(int argc, char **argv)
DOCA_LOG_REGISTER(DECOMPRESS_DEFLATE::MAIN)
doca_error_t decompress_deflate(struct compress_cfg *cfg, char *file_data, size_t file_size)
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_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
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
char file_path[MAX_FILE_NAME]
char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]
char output_path[MAX_FILE_NAME]
doca_error_t read_file(char const *path, char **out_bytes, size_t *out_bytes_len)
Definition: utils.c:56