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

Generated by: LCOV version 1.14