LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/sandesh/library/c - sandesh.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 13 13 100.0 %
Date: 2026-08-03 02:19:58 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : /*
       6             :  * sandesh.h
       7             :  *
       8             :  * Sandesh C Library
       9             :  */
      10             : 
      11             : #ifndef __SANDESHC_H__
      12             : #define __SANDESHC_H__
      13             : 
      14             : #ifdef __cplusplus
      15             : extern "C" {
      16             : #endif
      17             : 
      18             : /* OS specific defines */
      19             : #ifdef __KERNEL__
      20             : #if defined(__linux__)
      21             : #include <linux/kernel.h>
      22             : #include <linux/slab.h>
      23             : 
      24             : #include <linux/types.h>
      25             : #include <linux/in.h>
      26             : #include <linux/in6.h>
      27             : 
      28             : #define OS_LOG_ERR KERN_ERR
      29             : #define OS_LOG_DEBUG KERN_DEBUG
      30             : 
      31             : #define os_malloc(size)                  kmalloc(size, GFP_KERNEL)
      32             : #define os_zalloc(size)                  kzalloc(size, GFP_KERNEL)
      33             : #define os_realloc(ptr, size)            krealloc(ptr, size, GFP_KERNEL)
      34             : #define os_free(ptr)                     kfree(ptr)
      35             : #define os_log(level, format, arg...)    printk(level format, ##arg)
      36             : #endif
      37             : 
      38             : extern int vrouter_dbg;
      39             : #else /* __KERNEL__ */
      40             : 
      41             : #include <stdlib.h>
      42             : #include <string.h>
      43             : #include <sys/types.h>
      44             : #include <arpa/inet.h>
      45             : 
      46             : #include <syslog.h>
      47             : #include <sys/errno.h>
      48             : 
      49             : #define OS_LOG_ERR LOG_ERR
      50             : #define OS_LOG_DEBUG LOG_DEBUG
      51             : 
      52             : #define os_malloc(size)                  malloc(size)
      53             : #define os_zalloc(size)                  calloc(1, size)
      54             : #define os_realloc(ptr, size)            realloc(ptr, size)
      55             : #define os_free(ptr)                     free(ptr)
      56             : #define os_log(level, format, arg...)    syslog(level, format, ##arg)
      57             : 
      58             : 
      59             : #endif /* __KERNEL__ */
      60             : 
      61             : typedef unsigned char ct_uuid_t[16];
      62             : 
      63             : typedef struct ipaddr_s {
      64             :     uint8_t iptype; // AF_INET or AF_INET6
      65             :     union {
      66             :         struct in_addr ipv4;
      67             :         struct in6_addr ipv6;
      68             :     };
      69             : } ipaddr_t;
      70             : 
      71       33032 : static inline uint64_t os_get_value64(const uint8_t *data) {
      72       33032 :     uint64_t value = 0;
      73       33032 :     int i = 0;
      74      297288 :     for (; i < 8; ++i) {
      75      264256 :         if (i) value <<= 8;
      76      264256 :         value += *data++;
      77             :     }
      78       33032 :     return value;
      79             : }
      80             : 
      81       33032 : static inline void os_put_value64(uint8_t *data, uint64_t value) {
      82       33032 :     int i = 0, offset;
      83      297288 :     for (; i < 8; i++) {
      84      264256 :         offset = (8 - (i + 1)) * 8;
      85      264256 :         *data++ = ((value >> offset) & 0xff);
      86             :     }
      87       33032 : }
      88             : 
      89             : #include "thrift.h"
      90             : #include "transport/thrift_transport.h"
      91             : #include "transport/thrift_memory_buffer.h"
      92             : #include "transport/thrift_fake_transport.h"
      93             : #include "transport/thrift_file_transport.h"
      94             : #include "protocol/thrift_protocol.h"
      95             : #include "protocol/thrift_binary_protocol.h"
      96             : #include "protocol/thrift_xml_protocol.h"
      97             : 
      98             : typedef struct sandesh_info_s {
      99             :     const char *name;
     100             :     u_int32_t size;
     101             :     int32_t (*read) (void *, ThriftProtocol *, int *);
     102             :     int32_t (*read_binary_from_buffer) (void *, uint8_t *, const size_t, int *);
     103             :     int32_t (*write) (void *, ThriftProtocol *, int *);
     104             :     int32_t (*write_binary_to_buffer) (void *, uint8_t *, const size_t, int *);
     105             :     void (*process) (void *);
     106             :     void (*free) (void *);
     107             : } sandesh_info_t ;
     108             : 
     109             : typedef sandesh_info_t * (*sandesh_find_info_fn) (const char *name);
     110             : 
     111             : sandesh_info_t * sandesh_find_info(sandesh_info_t *infos, const char *name);
     112             : int32_t sandesh_decode(u_int8_t *buf, u_int32_t buf_len,
     113             :                        sandesh_find_info_fn sinfo_find_fn, int *error);
     114             : int32_t sandesh_encode(void *sandesh, const char *sname,
     115             :                        sandesh_find_info_fn sinfo_find_fn, u_int8_t *buf,
     116             :                        u_int32_t buf_len, int *error);
     117             : int32_t sandesh_get_encoded_length(void *sandesh, const char *sname,
     118             :                                    sandesh_find_info_fn sinfo_find_fn,
     119             :                                    int *error);
     120             : 
     121             : #ifdef __cplusplus
     122             : }
     123             : #endif
     124             : 
     125             : #endif /* __SANDESHC_H__ */

Generated by: LCOV version 1.14