主题: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;
}