libxcoder  3.5.1
init_rsrc_logan.c
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (C) 2022 NETINT Technologies
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18  * SOFTWARE.
19  *
20  ******************************************************************************/
21 
22 /*!*****************************************************************************
23  *
24  * \file init_rsrc_logan.c
25  *
26  * @date April 1, 2018
27  *
28  * \brief NETINT T4XX resource init utility program
29  *
30  * @author
31  *
32  ******************************************************************************/
33 
34 #include <stdio.h>
35 #include <string.h>
36 #include <fcntl.h>
37 
38 #if defined(__linux__) || defined(__APPLE__)
39 #include <unistd.h>
40 #include <sys/types.h>
41 #elif _WIN32
42 #include "ni_getopt_logan.h"
43 #endif
44 
45 #include "ni_defs_logan.h"
46 #include "ni_rsrc_api_logan.h"
47 #include "ni_rsrc_priv_logan.h"
48 #include "ni_util_logan.h"
49 
50 static void display_help(void)
51 {
52  printf("-------- init_rsrc_logan v%s --------\n"
53  "Initialize NetInt Logan transcoder resource pool\n"
54  "-r Init transcoder card resource regardless firmware release \n"
55  " version to libxcoder_logan version compatibility.\n"
56  " Default: only init cards with compatible firmware version.\n"
57  "-c Only init if all cards are fully compatible.\n"
58  " Default: init as many fully and partially cards as possible.\n"
59  "-t Set timeout time in seconds for device polling, will exit with failure \n"
60  " if reached.\n"
61  " Default: no timeout.\n"
62  "-l Set loglevel of libxcoder_logan API.\n"
63  " [none, fatal, error, info, debug, trace]\n"
64  " Default: info\n"
65  "-v Show libxcoder_logan version.\n"
66  "-h Display this help and exit.\n", NI_LOGAN_XCODER_REVISION);
67 }
68 
69 /*!******************************************************************************
70  * \brief
71  *
72  * \param
73  *
74  * \return
75  *******************************************************************************/
76 int main(int argc, char *argv[])
77 {
78  ni_logan_retcode_t retval;
79  int init_no_compat_check = 0;
80  int init_only_if_full_compat = 0;
81  int should_match_rev = 1;
82  int opt;
83  int timeout_seconds = 0;
84 
85  // arg handling
86  while ((opt = getopt(argc, argv, "hvrct:l:")) != -1)
87  {
88  switch (opt)
89  {
90  case 'h':
91  // help message
92  display_help();
93  return 0;
94  case 'r':
95  init_no_compat_check = 1;
96  break;
97  case 'c':
98  init_only_if_full_compat = 1;
99  break;
100  case 't':
101  timeout_seconds = atoi(optarg);
102  printf("Timeout will be set %d\n", timeout_seconds);
103  break;
104  case 'l':
105  if (!strcmp(optarg, "none")) {
107  } else if (!strcmp(optarg, "fatal")) {
109  } else if (!strcmp(optarg, "error")) {
111  } else if (!strcmp(optarg, "info")) {
113  } else if (!strcmp(optarg, "debug")) {
115  } else if (!strcmp(optarg, "trace")) {
117  } else {
118  fprintf(stderr, "unknown log level selected: %s", optarg);
119  return 1;
120  }
121  break;
122  case 'v':
123  printf("%s\n", NI_LOGAN_XCODER_REVISION);
124  return 0;
125  default:
126  fprintf(stderr, "Wrong option\n");
127  return 1;
128  }
129  }
130 
131  if (init_no_compat_check && init_only_if_full_compat)
132  {
133  fprintf(stderr, "Error: -r option cannot be used with -c option\n\n");
134  display_help();
135  return 1;
136  }
137  if (init_no_compat_check)
138  {
139  should_match_rev = 0;
140  }
141  else if (init_only_if_full_compat)
142  {
143  should_match_rev = 2;
144  }
145 
146 #if defined(__linux__) || defined(__APPLE__)
147  retval = ni_logan_rsrc_init(should_match_rev, timeout_seconds);
148  if (retval > 0 && retval != NI_LOGAN_RETCODE_INIT_ALREADY)
150  return retval;
151 #elif _WIN32
152  retval = ni_logan_rsrc_init(should_match_rev, timeout_seconds);
153  if (NI_LOGAN_RETCODE_SUCCESS == retval)
154  {
155  printf("NETINT Logan Resources Intitialized Successfully\n");
156  // keep the process only on success
157  // just return on init already or failure
158  while (1)
159  Sleep(1000);
160  }
161  return retval;
162 #endif
163 }
int main(int argc, char *argv[])
Common NETINT definitions used by all modules.
ni_logan_retcode_t
@ NI_LOGAN_RETCODE_SUCCESS
#define NI_LOGAN_RETCODE_INIT_ALREADY
#define NI_LOGAN_XCODER_REVISION
Definition: ni_defs_logan.h:62
#define atoi(p_str)
int getopt(int argc, char *argv[], const char *optstring)
char * optarg
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Definition: ni_log_logan.c:138
@ NI_LOG_NONE
Definition: ni_log_logan.h:62
@ NI_LOG_DEBUG
Definition: ni_log_logan.h:66
@ NI_LOG_TRACE
Definition: ni_log_logan.h:67
@ NI_LOG_FATAL
Definition: ni_log_logan.h:63
@ NI_LOG_ERROR
Definition: ni_log_logan.h:64
@ NI_LOG_INFO
Definition: ni_log_logan.h:65
int ni_logan_rsrc_init(int should_match_rev, int timeout_seconds)
Initialize and create all resources required to work with NETINT NVMe transcoder devices....
Exported definitions related to resource management of NI T-408 devices.
Private definitions related to resource management of NI T-408 devices.
Exported utility routines definition.