A source code for a complete sample interface module.
#include <stdlib.h>
#include <string.h>
#include "openavb_types_pub.h"
#include "openavb_trace_pub.h"
#define AVB_LOG_COMPONENT "Echo Interface"
#include "openavb_log_pub.h"
typedef struct {
char *pEchoString;
bool increment;
bool txLocalEcho;
bool noNewline;
bool ignoreTimestamp;
} pvt_data_t;
void openavbIntfEchoCfgCB(
media_q_t *pMediaQ,
const char *name,
const char *value)
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF);
if (pMediaQ) {
char *pEnd;
long tmp;
if (!pPvtData) {
AVB_LOG_ERROR("Private interface module data not allocated.");
return;
}
if (strcmp(name, "intf_nv_echo_string") == 0) {
if (pPvtData->pEchoString)
free(pPvtData->pEchoString);
pPvtData->pEchoString = strdup(value);
if (pPvtData->pEchoString) {
pPvtData->echoStringLen = strlen(pPvtData->pEchoString);
}
}
else if (strcmp(name, "intf_nv_echo_string_repeat") == 0) {
pPvtData->echoStringRepeat = strtol(value, &pEnd, 10);
if (pPvtData->echoStringRepeat > 1 && pPvtData->pEchoString) {
char *pEchoStringRepeat = calloc(1, (pPvtData->echoStringLen * pPvtData->echoStringRepeat) + 1);
int i1;
for (i1 = 0; i1 < pPvtData->echoStringRepeat; i1++) {
strcat(pEchoStringRepeat, pPvtData->pEchoString);
}
free(pPvtData->pEchoString);
pPvtData->pEchoString = pEchoStringRepeat;
pPvtData->echoStringLen = strlen(pPvtData->pEchoString);
}
}
else if (strcmp(name, "intf_nv_echo_increment") == 0) {
tmp = strtol(value, &pEnd, 10);
if (*pEnd == '\0' && tmp == 1) {
pPvtData->increment = (tmp == 1);
}
}
else if (strcmp(name, "intf_nv_tx_local_echo") == 0) {
tmp = strtol(value, &pEnd, 10);
if (*pEnd == '\0' && tmp == 1) {
pPvtData->txLocalEcho = (tmp == 1);
}
}
else if (strcmp(name, "intf_nv_echo_no_newline") == 0) {
tmp = strtol(value, &pEnd, 10);
if (*pEnd == '\0' && tmp == 1) {
pPvtData->noNewline = (tmp == 1);
}
}
else if (strcmp(name, "intf_nv_ignore_timestamp") == 0) {
tmp = strtol(value, &pEnd, 10);
if (*pEnd == '\0' && tmp == 1) {
pPvtData->ignoreTimestamp = (tmp == 1);
}
}
}
AVB_TRACE_EXIT(AVB_TRACE_INTF);
}
void openavbIntfEchoGenInitCB(
media_q_t *pMediaQ)
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF);
AVB_TRACE_EXIT(AVB_TRACE_INTF);
}
void openavbIntfEchoTxInitCB(
media_q_t *pMediaQ)
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF);
if (pMediaQ) {
if (!pPvtData) {
AVB_LOG_ERROR("Private interface module data not allocated.");
return;
}
pPvtData->Counter = 0;
}
AVB_TRACE_EXIT(AVB_TRACE_INTF);
}
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF_DETAIL);
if (pMediaQ) {
if (!pPvtData) {
AVB_LOG_ERROR("Private interface module data not allocated.");
}
if (pMediaQItem) {
if (pMediaQItem->
itemSize >= pPvtData->increment ? pPvtData->echoStringLen + 16 : pPvtData->echoStringLen) {
if (pPvtData->increment) {
int len = sprintf(pMediaQItem->
pPubData,
"%s %u", pPvtData->pEchoString, pPvtData->Counter++);
}
else {
memcpy(pMediaQItem->
pPubData, pPvtData->pEchoString, pPvtData->echoStringLen);
pMediaQItem->
dataLen = pPvtData->echoStringLen;
}
}
else {
}
if (pPvtData->txLocalEcho) {
if (pPvtData->noNewline)
printf(
"%s ", (
char *)pMediaQItem->
pPubData);
else
printf(
"%s\n\r", (
char *)pMediaQItem->
pPubData);
}
AVB_TRACE_EXIT(AVB_TRACE_INTF_DETAIL);
}
else {
AVB_TRACE_EXIT(AVB_TRACE_INTF_DETAIL);
}
}
AVB_TRACE_EXIT(AVB_TRACE_INTF_DETAIL);
}
void openavbIntfEchoRxInitCB(
media_q_t *pMediaQ)
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF);
if (pMediaQ) {
if (!pPvtData) {
AVB_LOG_ERROR("Private interface module data not allocated.");
return;
}
pPvtData->Counter = 0;
}
AVB_TRACE_EXIT(AVB_TRACE_INTF);
}
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF_DETAIL);
if (pMediaQ) {
if (!pPvtData) {
AVB_LOG_ERROR("Private interface module data not allocated.");
}
while (moreItems) {
if (pMediaQItem) {
}
if (pPvtData->noNewline) {
printf(
"%s ", (
char *)pMediaQItem->
pPubData);
}
else {
if (pPvtData->increment) {
printf(
"%s : %u\n\r", (
char *)pMediaQItem->
pPubData, pPvtData->Counter++);
}
else {
printf(
"%s\n\r", (
char *)pMediaQItem->
pPubData);
}
}
}
}
else {
}
}
}
AVB_TRACE_EXIT(AVB_TRACE_INTF_DETAIL);
}
void openavbIntfEchoEndCB(
media_q_t *pMediaQ)
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF);
AVB_TRACE_EXIT(AVB_TRACE_INTF);
}
void openavbIntfEchoGenEndCB(
media_q_t *pMediaQ)
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF);
if (pMediaQ) {
if (!pPvtData) {
AVB_LOG_ERROR("Private interface module data not allocated.");
return;
}
if (pPvtData->pEchoString) {
free(pPvtData->pEchoString);
pPvtData->pEchoString =
NULL;
}
}
AVB_TRACE_EXIT(AVB_TRACE_INTF);
}
{
AVB_TRACE_ENTRY(AVB_TRACE_INTF);
if (pMediaQ) {
AVB_LOG_ERROR("Unable to allocate memory for AVTP interface module.");
}
pPvtData->pEchoString =
NULL;
pPvtData->echoStringRepeat = 1;
pPvtData->echoStringLen = 0;
pPvtData->increment =
FALSE;
pPvtData->txLocalEcho =
FALSE;
pPvtData->noNewline =
FALSE;
pPvtData->ignoreTimestamp =
FALSE;
}
AVB_TRACE_EXIT(AVB_TRACE_INTF);
}