📄 rvremoteloglistener.c
字号:
/************************************************************************
File Name : rvRemoteLogListener.c
Description :
*************************************************************************
Copyright (c) 2001 , RADVision, Inc. All rights reserved.
*************************************************************************
NOTICE:
This document contains information that is proprietary to RADVision Inc.
No part of this publication may be reproduced in any form whatsoever
without written prior approval by RADVision Inc.
RADVision Inc. reserves the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
*************************************************************************
$Revision: $
$Date: 03/01/2001 $
$Author: Scott K. Eaton $
************************************************************************/
#include "rvremoteloglistener.h"
#include "rvdefalloc.h"
#include "rvdatabuffer.h"
#include "rvsocket_.h"
#include <stdio.h>
#if (RV_LOGMASK != RV_LOGMASK_NONE)
#define RV_REMOTELOG_MAX_BUFFER_SIZE 1024
/***********************************************************************
* Utility methods
************************************************************************/
void rvLogRecordSerialize(const RvLogRecord *thisPtr, RvDataBuffer *bufferPtr)
{
RvUint32 length;
/* Copy record into the buffer */
length = strlen(thisPtr->text);
rvDataBufferWriteUint8Array(bufferPtr, thisPtr->text, length);
rvDataBufferWriteUint32(bufferPtr, length);
rvDataBufferWriteUint32(bufferPtr, thisPtr->level);
length = strlen(thisPtr->threadName);
rvDataBufferWriteUint8Array(bufferPtr, thisPtr->threadName, length);
rvDataBufferWriteUint32(bufferPtr, length);
rvDataBufferWriteUint32(bufferPtr, rvTimespecSecs(&thisPtr->timestamp));
rvDataBufferWriteUint32(bufferPtr, rvTimespecNsecs(&thisPtr->timestamp));
}
RvBool rvSocketSendDataBufferTo(RvSocket *thisPtr, RvDataBuffer *bufferPtr, const RvSocketAddr* toAddrPtr)
{
return (rvSocketSendTo_(*thisPtr, (char*)rvDataBufferGetData(bufferPtr),
rvDataBufferGetLength(bufferPtr), 0, toAddrPtr) < 0);
}
/***********************************************************************
* RvRemoteLogListener
************************************************************************/
static void NewRecordEvent(const RvLogRecord *recordPtr, void *dataPtr)
{
RvRemoteLogListener *thisPtr = (RvRemoteLogListener *)dataPtr;
if(thisPtr->mode == RV_REMOTELOGLISTENER_MODE_BINARY)
{
/* Reset the buffer */
rvDataBufferSetDataPosition(&thisPtr->buffer,RV_REMOTELOG_MAX_BUFFER_SIZE,0);
/* Copy record into buffer */
rvLogRecordSerialize(recordPtr,&thisPtr->buffer);
/* Send the buffer */
rvSocketSendDataBufferTo(&thisPtr->socket, &thisPtr->buffer, &thisPtr->address);
}
else
{
int length;
char buffer[1024];
char timeString[32];
length = sprintf(buffer, "%s|%s|%s|%s",
rvLogRecordGetTimeAsString(recordPtr,timeString),
rvLogRecordGetThreadName(recordPtr),
rvLogRecordGetLevelString(recordPtr),
rvLogRecordGetText(recordPtr));
/* under-score method is used to avoid logging in normal rvSocketSendTo */
rvSocketSendTo_(thisPtr->socket, buffer, length, 0, &thisPtr->address);
}
}
/*$
{function:
{name: rvRemoteLogListenerConstruct}
{class: RvRemoteLogListener}
{include: rvremoteloglistener.h}
{description:
{p: This method constructs a RvRemoteLogListener.}
}
{proto: RvRemoteLogListener* rvRemoteLogListenerConstruct(RvRemoteLogListener* thisPtr, RvLogMask mask, const char *address, RvInetPort port, RvRemoteLogListenerMode mode);}
{params:
{param: {n:thisPtr} {d:The RvRemoteLogListener object.}}
{param: {n:mask} {d:The log level mask to filter log records with.}}
{param: {n:address} {d:The inet address to send to. If a NULL string
is passed in then the local address will be used. If
the host is multihomed the first interface will be used.}}
{param: {n:port} {d:The inet port to send to.}}
{param: {n:mode} {d:The mode to run in.}}
}
{returns: A pointer to the RvRemoteLogListener object if the object
constructs sucessfully, NULL otherwise. }
}
$*/
RvRemoteLogListener* rvRemoteLogListenerConstruct(RvRemoteLogListener* thisPtr, RvLogMask mask, const char *address, RvInetPort port, RvRemoteLogListenerMode mode)
{
if(address != NULL)
{
rvSocketAddrConstructInetByName(&thisPtr->address, address, port);
}
else
{
RvHost host;
rvHostConstructLocal(&host);
rvSocketAddrConstructInet(&thisPtr->address, &host, 0, port);
rvHostDestruct(&host);
}
rvLogListenerConstruct(&thisPtr->listener, mask, NewRecordEvent, thisPtr);
rvSocketConstructUdp(&thisPtr->socket, 0);
thisPtr->mode = mode;
rvDataBufferConstruct(&thisPtr->buffer,RV_REMOTELOG_MAX_BUFFER_SIZE,0,&rvDefaultAlloc);
return thisPtr;
}
/*$
{function:
{name: rvRemoteLogListenerDestruct}
{class: RvRemoteLogListener}
{include: rvremoteloglistener.h}
{description:
{p: This method destroys a RvRemoteLogListener, freeing any resources
it held.}
}
{proto: void rvRemoteLogListenerDestruct(RvRemoteLogListener* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvRemoteLogListener object to destroy.}}
}
}
$*/
void rvRemoteLogListenerDestruct(RvRemoteLogListener* thisPtr)
{
rvDataBufferDestruct(&thisPtr->buffer);
rvLogListenerDestruct(&thisPtr->listener);
rvSocketDestruct(&thisPtr->socket);
rvSocketAddrDestruct(&thisPtr->address);
}
/*$
{function:
{name: rvRemoteLogListenerSetAddress}
{class: RvRemoteLogListener}
{include: rvremoteloglistener.h}
{description:
{p: This method sets the destination address to which a RvRemoteLogListener sends Log Records.}
}
{proto: void rvRemoteLogListenerSetAddress(RvRemoteLogListener* thisPtr, const char *address, RvInetPort port);}
{params:
{param: {n:thisPtr} {d:The RvRemoteLogListener object.}}
{param: {n:address} {d:The inet address to send to.}}
{param: {n:port} {d:The inet port to send to.}}
}
{notes:
{note: This function can only be called on RvRemoteLogListeners that are not currently registered with any log.
i.e. you must unregister the RvRemoteLogListener from the log before setting the address. }
}
}
$*/
void rvRemoteLogListenerSetAddress(RvRemoteLogListener* thisPtr, const char *address, RvInetPort port) {
rvSocketAddrDestruct(&thisPtr->address);
rvSocketAddrConstructInetByName(&thisPtr->address, address, port);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -