summaryrefslogtreecommitdiffstats
path: root/nsframework/backup_manager/server/src/bkup_param.cpp
blob: 900779baa6a4db9daab7977d286051d3883f6522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <other_service/VP_GetEnv.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <libxml/xmlerror.h>
#include <libxml/parser.h>
#include <libxml/SAX2.h>
#include <inttypes.h>
#include <cerrno>
#include <cstdio>
#include <string>
#include <map>
#include <utility>
#include "bkup_param.h"
#include "bkup_backupmanagerlog.h"
#include "bkup_util.h"

#define BKUP_XML_PATH_MAX 100
#define BKUP_XML_PATH "/usr/agl/conf/BS/ns/backup_manager/rodata/"
#define BKUP_XML_PREFIX "backup_"
#define BKUP_XML_EXTENSION ".xml"

#define BKUP_AREA_1  "AREA1"
#define BKUP_AREA_2  "AREA2"
#define BKUP_BRAND_1 "BRAND1"
#define BKUP_BRAND_2 "BRAND2"
#define BKUP_GRADE_1 "GRADE1"
#define BKUP_GRADE_2 "GRADE2"
#define BKUP_DESTINATION_TYPE_AREA1_TE "AREA1_TE"
#define BKUP_DESTINATION_TYPE_AREA1_L  "AREA1_L"
#define BKUP_DESTINATION_TYPE_AREA2_T  "AREA2_T"
#define BKUP_DESTINATION_TYPE_AREA2_TE "AREA2_TE"

#define BKUP_DESTINATION_STR_MAX 10
typedef struct {
  char area[VP_MAX_LENGTH];
  char brand[VP_MAX_LENGTH];
  char grade[VP_MAX_LENGTH];
  char destination[BKUP_DESTINATION_STR_MAX];
} BkupDestinationTbl;

const BkupDestinationTbl kDestinationTbl[] = {
    // Destination:Area1
    {BKUP_AREA_1, BKUP_BRAND_1, BKUP_GRADE_1, BKUP_DESTINATION_TYPE_AREA1_TE},
    {BKUP_AREA_1, BKUP_BRAND_1, BKUP_GRADE_2, BKUP_DESTINATION_TYPE_AREA1_TE},
    {BKUP_AREA_1, BKUP_BRAND_2, BKUP_GRADE_1, BKUP_DESTINATION_TYPE_AREA1_L},
    {BKUP_AREA_1, BKUP_BRAND_2, BKUP_GRADE_2, BKUP_DESTINATION_TYPE_AREA1_L},
    // Destination:Area2
    {BKUP_AREA_2, BKUP_BRAND_1, BKUP_GRADE_1,   BKUP_DESTINATION_TYPE_AREA2_TE},
    {BKUP_AREA_2, BKUP_BRAND_1, BKUP_GRADE_2,   BKUP_DESTINATION_TYPE_AREA2_TE},
    {BKUP_AREA_2, BKUP_BRAND_2, BKUP_GRADE_1,   BKUP_DESTINATION_TYPE_AREA2_T},
    {BKUP_AREA_2, BKUP_BRAND_2, BKUP_GRADE_2,   BKUP_DESTINATION_TYPE_AREA2_T},
};

typedef std::string Category;
typedef struct {
  bool nand;
  bool cache_dram;
  bool backup_dram;
  bool sync;
  bool encrypt;
  int backup_cycle;
} CategoryProperty;
typedef std::map<Category, CategoryProperty> CategoryTable;

typedef std::string Item;
typedef struct {
  int id;
  int size;
  void *opt;
  Category category;
} ItemProperty;  // LCOV_EXCL_BR_LINE 11:except,C++ STL
typedef std::map<Item, ItemProperty> ItemTable;
typedef std::map<int, Item> IdTable;

typedef struct {
  Category current;
  CategoryTable category_table;
  ItemTable item_table;
  IdTable id_table;
} BackupParams;  // LCOV_EXCL_BR_LINE 11:except,C++ STL

static BackupParams *g_backup_params = NULL;

static void StartElementNs(void *ctx, const xmlChar *localname,
                           const xmlChar *prefix, const xmlChar *uri,
                           int nb_namespaces, const xmlChar **namespaces,
                           int nb_attributes, int nb_defaulted,
                           const xmlChar **attributes) {
  if (ctx == NULL) {
    FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "ctx is NULL");
    return;
  }
  if (localname == NULL) {
    FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "localname is NULL");
    return;
  }
  BackupParams *p_backup_params = static_cast<BackupParams *>(ctx);
  std::string tag = (const char *)localname;  // LCOV_EXCL_BR_LINE 11:except,C++ STL
  if (tag.compare("backup") == 0) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    // do nothing
  } else if (tag.compare("category") == 0) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    CategoryProperty category_attr = {false, false, false, false, false, 0};
    std::string category_name;  // LCOV_EXCL_BR_LINE 11:except,C++ STL

    for (int i = 0; i < nb_attributes; i++) {
      // LCOV_EXCL_BR_START 11:except,C++ STL
      std::string localname = (const char *)attributes[i * 5];
      std::string value((const char *)attributes[i * 5 + 3], (const char *)attributes[i * 5 + 4]);
      if (localname.compare("name") == 0) {
        category_name = value;
      } else if (localname.compare("nand") == 0) {
        if (value.compare("true") == 0) {
          category_attr.nand = true;
        }
      } else if (localname.compare("backupDram") == 0) {
        if (value.compare("true") == 0) {
          category_attr.backup_dram = true;
        }
      } else if (localname.compare("cacheDram") == 0) {
        if (value.compare("true") == 0) {
          category_attr.cache_dram = true;
        }
      } else if (localname.compare("sync") == 0) {
        if (value.compare("true") == 0) {
          category_attr.sync = true;
        }
      } else if (localname.compare("encrypt") == 0) {
        if (value.compare("true") == 0) {
          category_attr.encrypt = true;
        }
      } else if (localname.compare("backupCycle") == 0) {
        category_attr.backup_cycle = atoi(value.c_str());
      // LCOV_EXCL_BR_STOP 11:except,C++ STL
      } else {
        // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
        FRAMEWORKUNIFIEDLOG(ZONE_WARN, __func__, "Unknown attribute:%s", localname.c_str());
        // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h"
      }
    }

    // LCOV_EXCL_BR_START 11:except,C++ STL
    CategoryTable::iterator c_it = p_backup_params->category_table.find(category_name);
    // LCOV_EXCL_BR_STOP 11:except,C++ STL
    if (c_it != p_backup_params->category_table.end()) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
      // LCOV_EXCL_START 200:Execute in server start period
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "duplicate category:%s", category_name.c_str());
      exit(EXIT_FAILURE);
      // LCOV_EXCL_STOP 200:Execute in server start period
    }
    // LCOV_EXCL_BR_START 11:except,C++ STL
    p_backup_params->category_table.insert(std::make_pair(category_name, category_attr));
    // LCOV_EXCL_BR_STOP 11:except,C++ STL
    p_backup_params->current = category_name;  // LCOV_EXCL_BR_LINE 11:except,C++ STL
  } else if (tag.compare("item") == 0) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    if (p_backup_params->current.compare("") == 0) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
      // LCOV_EXCL_START 200:Execute in server start period
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Detect item before category");
      exit(EXIT_FAILURE);
      // LCOV_EXCL_STOP 200:Execute in server start period
    }

    ItemProperty item_property = {0, 0, NULL, p_backup_params->current};  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    std::string item_name;  // LCOV_EXCL_BR_LINE 11:except,C++ STL

    for (int i = 0; i < nb_attributes; i++) {
      // LCOV_EXCL_BR_START 11:except,C++ STL
      std::string localname = (const char *)attributes[i * 5];
      std::string value((const char *)attributes[i * 5 + 3], (const char *)attributes[i * 5 + 4]);
      if (localname.compare("name") == 0) {
        item_name = value;
      } else if (localname.compare("id") == 0) {
        item_property.id = atoi(value.c_str());
      } else if (localname.compare("size") == 0) {
        item_property.size = atoi(value.c_str());
      // LCOV_EXCL_BR_STOP 11:except,C++ STL
      } else {
        // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
        FRAMEWORKUNIFIEDLOG(ZONE_WARN, __func__, "Unknown attribute:%s", localname.c_str());
        // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h"
      }
    }

    ItemTable::iterator i_it = p_backup_params->item_table.find(item_name);  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    if (i_it != p_backup_params->item_table.end()) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
      // LCOV_EXCL_START 200:Execute in server start period
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Duplicate item:%s", item_name.c_str());
      exit(EXIT_FAILURE);
      // LCOV_EXCL_STOP 200:Execute in server start period
    }
    // LCOV_EXCL_BR_START 11:except,C++ STL
    p_backup_params->item_table.insert(std::make_pair(item_name, item_property));
    // LCOV_EXCL_BR_STOP 11:except,C++ STL

    IdTable::iterator id_it = p_backup_params->id_table.find(item_property.id);  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    if (id_it != p_backup_params->id_table.end()) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
      // LCOV_EXCL_START 200:Execute in server start period
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Duplicate id:%d", item_property.id);
      exit(EXIT_FAILURE);
      // LCOV_EXCL_STOP 200:Execute in server start period
    }
    // LCOV_EXCL_BR_START 11:except,C++ STL
    p_backup_params->id_table.insert(std::make_pair(item_property.id, item_name));
    // LCOV_EXCL_BR_STOP 11:except,C++ STL
  } else {
    // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
    FRAMEWORKUNIFIEDLOG(ZONE_WARN, __func__, "Unknown tag:%s", localname);
    // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h"
  }
}

static int BkupGetXmlPath(char* path) {
  if (path == NULL) {  // LCOV_EXCL_BR_LINE 6:Excluded as no NULL is currently passed
    // LCOV_EXCL_START 6:Excluded as no NULL is currently passed
    AGL_ASSERT_NOT_TESTED();
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "path is NULL");
    return -1;
    // LCOV_EXCL_STOP 6:Excluded as no NULL is currently passed
  }
  memset(path, 0, BKUP_XML_PATH_MAX);
  char param_area[VP_MAX_LENGTH] = "";
  VP_GetEnv(VP_VEHICLEPARAMETERLIBRARY_AREA, param_area);
  char param_brand[VP_MAX_LENGTH] = "";
  VP_GetEnv(VEHICLEPARAMETERLIBRARY_BRAND, param_brand);
  char param_grade[VP_MAX_LENGTH] = "";
  VP_GetEnv(VP_VEHICLEPARAMETERLIBRARY_GRADE, param_grade);

  bool is_match = false;
  for (uint16_t i = 0; i < _countof(kDestinationTbl); i++) {
    size_t area_size = static_cast<size_t>(std::string(kDestinationTbl[i].area).size());
    // Check vehicle parameter settings (For VP_VEHICLEPARAMETERLIBRALY_AREA only, check the area size of tbl to check the character strings common to each area)
    if ((strncmp(param_area, kDestinationTbl[i].area, area_size) == 0) &&
        (strncmp(param_brand, kDestinationTbl[i].brand, sizeof(param_area)) == 0) &&
        (strncmp(param_grade, kDestinationTbl[i].grade, sizeof(param_area)) == 0)) {
      is_match = true;
      snprintf(path, BKUP_XML_PATH_MAX, "%s%s%s%s", BKUP_XML_PATH, BKUP_XML_PREFIX,
               kDestinationTbl[i].destination, BKUP_XML_EXTENSION);
      break;
    }
  }
  if (is_match == false) {
    // If the destination settings do not match, set the AREA2_T path as failsafe
    snprintf(path, BKUP_XML_PATH_MAX, "%s%s%s%s", BKUP_XML_PATH, BKUP_XML_PREFIX,
             BKUP_DESTINATION_TYPE_AREA2_T, BKUP_XML_EXTENSION);
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Unexpected VP area[%s] brand[%s] grade[%s]",
           param_area, param_brand, param_grade);
  }
  return 0;
}

int BckupParamInit(void) {
  int ret = -1;
  xmlParserCtxtPtr xmlctx;
  xmlSAXHandler saxh;
  xmlDocPtr doc;
  int fd = -1;
  struct stat sb;
  char *map = NULL;
  uint64_t start, end;

  g_backup_params = new BackupParams;  // LCOV_EXCL_BR_LINE 11:except,C++ operator

  LIBXML_TEST_VERSION  // LCOV_EXCL_BR_LINE 11:unexpected branch
  // LCOV_EXCL_BR_START 11:unexpected branch
  xmlInitParser();  // NOLINT(readability/nolint) Defined in library of libxml
  // LCOV_EXCL_BR_STOP 11:unexpected branch

  memset(&saxh, 0, sizeof(saxh));
  saxh.initialized = XML_SAX2_MAGIC;
  saxh.startElementNs = StartElementNs;

  xmlctx = xmlCreatePushParserCtxt(&saxh, g_backup_params, NULL, 0, NULL);  // LCOV_EXCL_BR_LINE 11:unexpected branch

  char xml_path[BKUP_XML_PATH_MAX] = {0};
  ret = BkupGetXmlPath(xml_path);
  if (ret != 0) {  // LCOV_EXCL_BR_LINE 6:Excluded because the return value does not cause an error
    // LCOV_EXCL_START 6:Excluded because the return value does not cause an error
    AGL_ASSERT_NOT_TESTED();
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "BkupGetXmlPath Error");
    goto exit;
    // LCOV_EXCL_STOP 6:Excluded because the return value does not cause an error
  }

  if ((fd = open(xml_path, O_RDONLY)) < 0) {  // LCOV_EXCL_BR_LINE 5:open's error case.
    // LCOV_EXCL_START 5:open's error case.
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "open:%s", strerror(errno));
    goto exit;
    // LCOV_EXCL_STOP 5:open's error case.
  }
  if (fstat(fd, &sb) < 0) {  // LCOV_EXCL_BR_LINE 5:fstat's error case.
    // LCOV_EXCL_START 5:fstat's error case.
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "fstat:%s", strerror(errno));
    goto exit;
    // LCOV_EXCL_STOP 5:fstat's error case.
  }
  map = reinterpret_cast<char *>(mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0));
  if (map == MAP_FAILED) {  // LCOV_EXCL_BR_LINE 5:mmap's error case.
    // LCOV_EXCL_START 5:mmap's error case.
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "mmap:%s", strerror(errno));
    goto exit;
    // LCOV_EXCL_STOP 5:mmap's error case.
  }

  start = BkupTimerReal();
  if (xmlParseChunk(xmlctx, map, static_cast<int>(sb.st_size), 1)) {  // LCOV_EXCL_BR_LINE 5:xmlParseChunk's error case.
    // LCOV_EXCL_START 5:xmlParseChunk's error case.
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    xmlParserError(xmlctx, "xmlParseChunk");
    goto exit;
    // LCOV_EXCL_STOP 5:xmlParseChunk's error case.
  }
  end = BkupTimerReal();
  // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __func__, "spent:%" PRIu64 ".%06" PRIu64 "ms",
         static_cast<uint64_t>((end - start) / 1000000),
         static_cast<uint64_t>((end - start) % 1000000));
  // LCOV_EXCL_BR_STOP 15:marco defined in "native_service/ns_logger_if.h"

  doc = xmlctx->myDoc;
  xmlFreeParserCtxt(xmlctx);  // LCOV_EXCL_BR_LINE 11:unexpected branch
  xmlFreeDoc(doc);  // LCOV_EXCL_BR_LINE 11:unexpected branch
  xmlCleanupParser();  // LCOV_EXCL_BR_LINE 11:unexpected branch
  ret = 0;

exit:
  if (fd >= 0) {  // LCOV_EXCL_BR_LINE 5:open's error case.
    if (close(fd) < 0) {  // LCOV_EXCL_BR_LINE 5:close's error case.
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, "close:%s", strerror(errno));  // LCOV_EXCL_LINE 5:close's error case.
    }
  }
  if (map) {  // LCOV_EXCL_BR_LINE 5:mmap's error case.
    if (munmap(map, sb.st_size) < 0) {  // LCOV_EXCL_BR_LINE 5:munmap's error case.
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, "munmap:%s", strerror(errno));  // LCOV_EXCL_LINE 5:munmap's error case.
    }
  }
  return ret;
}

int BkupParamGet(const char *item_name, bkup_query_result_t *result) {
  if (g_backup_params == NULL) {  // LCOV_EXCL_BR_LINE 6:g_backup_params will not be NULL
    // LCOV_EXCL_START 6:g_backup_params will not be NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Uninitialize call");
    return -1;
    // LCOV_EXCL_STOP 6:g_backup_params will not be NULL
  }
  if (result == NULL) {
    FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "result is NULL");
    return -1;
  }
  ItemTable::iterator item_it = g_backup_params->item_table.find(item_name);  // LCOV_EXCL_BR_LINE 11:except,C++ STL
  if (item_it == g_backup_params->item_table.end()) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    return -1;
  }

  // LCOV_EXCL_BR_START 11:except,C++ STL
  CategoryTable::iterator category_it = g_backup_params->category_table.find(item_it->second.category);
  // LCOV_EXCL_BR_STOP 11:except,C++ STL
  if (category_it == g_backup_params->category_table.end()) {  // LCOV_EXCL_BR_LINE 6:double check
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return -1;  // LCOV_EXCL_LINE 6:double check
  }

  // LCOV_EXCL_BR_START 11:except,C++ STL
  result->id = item_it->second.id;
  result->size = item_it->second.size;
  result->opt = item_it->second.opt;
  result->nand = category_it->second.nand;
  result->cache_dram = category_it->second.cache_dram;
  result->backup_dram = category_it->second.backup_dram;
  result->sync = category_it->second.sync;
  result->encrypt = category_it->second.encrypt;
  result->backup_cycle = category_it->second.backup_cycle;
  BkupStrlcpy(result->category_name, item_it->second.category.c_str(), sizeof(result->category_name));
  // LCOV_EXCL_BR_STOP 11:except,C++ STL

  return 0;
}

int BkupParamGetNumid(uint32_t num_id, bkup_query_result_t *result,
                      char *item_name, size_t item_name_size) {
  if (g_backup_params == NULL) {  // LCOV_EXCL_BR_LINE 6:g_backup_params will not be NULL
    // LCOV_EXCL_START 6:g_backup_params will not be NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Uninitialize call");
    return -1;
    // LCOV_EXCL_STOP 6:g_backup_params will not be NULL
  }

  // LCOV_EXCL_BR_START 11:except,C++ STL
  IdTable::iterator id_it = g_backup_params->id_table.find(static_cast<int>(num_id));
  // LCOV_EXCL_BR_STOP 11:except,C++ STL
  if (id_it == g_backup_params->id_table.end()) {  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    return -1;
  }
  BkupStrlcpy(item_name, id_it->second.c_str(), item_name_size);  // LCOV_EXCL_BR_LINE 11:except,C++ STL

  return BkupParamGet(id_it->second.c_str(), result);  // LCOV_EXCL_BR_LINE 11:except,C++ STL
}

void *BkupParamSetOpt(const char *item_name, void *opt) {
  if (g_backup_params == NULL) {  // LCOV_EXCL_BR_LINE 6:g_backup_params will not be NULL
    // LCOV_EXCL_START 6:g_backup_params will not be NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Uninitialize call");
    return reinterpret_cast<void *>((-1));
    // LCOV_EXCL_STOP 6:g_backup_params will not be NULL
  }

  ItemTable::iterator item_it = g_backup_params->item_table.find(item_name);  // LCOV_EXCL_BR_LINE 11:except,C++ STL
  if (item_it == g_backup_params->item_table.end()) {  // LCOV_EXCL_BR_LINE 6:double check
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    return reinterpret_cast<void *>((-1));   // LCOV_EXCL_LINE 6:double check
  }

  // LCOV_EXCL_BR_START 11:unexpected branch
  return __sync_val_compare_and_swap(&item_it->second.opt, NULL, opt);  // NOLINT(readability/nolint) Supplied by gcc
  // LCOV_EXCL_BR_STOP 11:unexpected branch
}