iqdotlog.c总结

主题:iq基本知识入门
时间:2021年1月6日
作者:ybb
参考:iqdotlog.c
D:\OAI\openairinterface5g-develop-20209018\openairinterface5g-develop\common\utils\T\tracer\logger\iqdotlog.c****总结

先定义了一个标签名为iqdotlog的结构体

struct iqdotlog {
  struct logger common;//结构体里面有结构体
  void *database;//数据库
  int i_arg;//i声明
  int q_arg;//q声明
};

static关键字

static void _event(void *p, event e)
{
  struct iqdotlog *l = p;//指向结构体的指针变量
  int i;
  float I, Q;//IQ以float形式存储

  if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)//如果filter没有set,则为NULL
    return;

  I = e.e[l->i_arg].i;
  Q = e.e[l->q_arg].i;

  for (i = 0; i < l->common.vsize; i++)
    l->common.v[i]->append(l->common.v[i], &I, &Q, 1);
}

指针与结构体的使用

logger *new_iqdotlog(event_handler *h, void *database,
    char *event_name, char *I, char *Q)
{
  struct iqdotlog *ret;
  int event_id;//事件id
  database_event_format f;//数据库事件格式
  int i;//int i

  ret = calloc(1, sizeof(struct iqdotlog)); //为一个结构体内的所有成员变量分配对应的内存
  if (ret == NULL) abort();

  ret->common.event_name = strdup(event_name);//strdup函数会先用malloc函数配置与参数S字符串相同的空间大小,然后将参数S字符串的内容复制到该内存地址,最后把该地址返回,改地址最后可以利用free函数释放
  
  if (ret->common.event_name == NULL) abort();
  ret->database = database;

  event_id = event_id_from_name(database, event_name);//事件id

  ret->common.handler_id = register_handler_function(h,event_id,_event,ret);

  f = get_format(database, event_id);

  /* look for args */
  ret->i_arg = -1;
  ret->q_arg = -1;
  for (i = 0; i < f.count; i++) {
    if (!strcmp(f.name[i], I)) ret->i_arg = i;
    if (!strcmp(f.name[i], Q)) ret->q_arg = i;
  }
  if (ret->i_arg == -1) {
    printf("%s:%d: argument '%s' not found in event '%s'\n",
        __FILE__, __LINE__, I, event_name);//参数i在事件内未找到
    abort();
  }
  if (ret->q_arg == -1) {
    printf("%s:%d: argument '%s' not found in event '%s'\n",
        __FILE__, __LINE__, Q, event_name);//参数q在事件内未找到
    abort();
  }
  if (strcmp(f.type[ret->i_arg], "int") != 0) {
    printf("%s:%d: argument '%s' has wrong type (should be 'int')\n",
        __FILE__, __LINE__, I);//参数类型错误
    abort();
  }
  if (strcmp(f.type[ret->q_arg], "int") != 0) {
    printf("%s:%d: argument '%s' has wrong type (should be 'int')\n",
        __FILE__, __LINE__, Q);//参数有错误的类型
    abort();
  }

  return ret;
}

附上代码文件:

#include "logger.h"
#include "logger_defs.h"
#include "handler.h"
#include "database.h"
#include "filter/filter.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

struct iqdotlog {
  struct logger common;//结构体里面有结构体
  void *database;//数据库
  int i_arg;//i声明
  int q_arg;//q声明
};

static void _event(void *p, event e)
{
  struct iqdotlog *l = p;//指向结构体的指针变量
  int i;
  float I, Q;//IQ以float形式存储

  if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)//如果filter没有set,则为NULL
    return;

  I = e.e[l->i_arg].i;
  Q = e.e[l->q_arg].i;

  for (i = 0; i < l->common.vsize; i++)
    l->common.v[i]->append(l->common.v[i], &I, &Q, 1);
}

logger *new_iqdotlog(event_handler *h, void *database,
    char *event_name, char *I, char *Q)
{
  struct iqdotlog *ret;
  int event_id;//事件id
  database_event_format f;//数据库事件格式
  int i;//int i

  ret = calloc(1, sizeof(struct iqdotlog)); //为一个结构体内的所有成员变量分配对应的内存
  if (ret == NULL) abort();

  ret->common.event_name = strdup(event_name);//strdup函数会先用malloc函数配置与参数S字符串相同的空间大小,然后将参数S字符串的内容复制到该内存地址,最后把该地址返回,改地址最后可以利用free函数释放
  
  if (ret->common.event_name == NULL) abort();
  ret->database = database;

  event_id = event_id_from_name(database, event_name);//事件id

  ret->common.handler_id = register_handler_function(h,event_id,_event,ret);

  f = get_format(database, event_id);

  /* look for args */
  ret->i_arg = -1;
  ret->q_arg = -1;
  for (i = 0; i < f.count; i++) {
    if (!strcmp(f.name[i], I)) ret->i_arg = i;
    if (!strcmp(f.name[i], Q)) ret->q_arg = i;
  }
  if (ret->i_arg == -1) {
    printf("%s:%d: argument '%s' not found in event '%s'\n",
        __FILE__, __LINE__, I, event_name);//参数i在事件内未找到
    abort();
  }
  if (ret->q_arg == -1) {
    printf("%s:%d: argument '%s' not found in event '%s'\n",
        __FILE__, __LINE__, Q, event_name);//参数q在事件内未找到
    abort();
  }
  if (strcmp(f.type[ret->i_arg], "int") != 0) {
    printf("%s:%d: argument '%s' has wrong type (should be 'int')\n",
        __FILE__, __LINE__, I);//参数类型错误
    abort();
  }
  if (strcmp(f.type[ret->q_arg], "int") != 0) {
    printf("%s:%d: argument '%s' has wrong type (should be 'int')\n",
        __FILE__, __LINE__, Q);//参数有错误的类型
    abort();
  }

  return ret;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值