[#1881] MainBuffe now robust to false ids on getData and putData

This commit is contained in:
Alexandre Savard
2009-07-28 16:23:58 -04:00
parent f808d247ca
commit 063e3720bb
3 changed files with 18 additions and 0 deletions

View File

@ -73,6 +73,12 @@ int MainBuffer::putData(void *buffer, int toCopy, unsigned short volume, CallID
RingBuffer* ring_buffer = getRingBuffer(call_id);
if (ring_buffer == NULL)
{
_debug("Input RingBuffer ID: \"%s\" does not exist!\n", call_id.c_str());
return 0;
}
int a;
ost::MutexLock guard (_mutex);
@ -95,6 +101,12 @@ int MainBuffer::getData(void *buffer, int toCopy, unsigned short volume, CallID
RingBuffer* ring_buffer = getRingBuffer(call_id);
if (ring_buffer == NULL)
{
_debug("Output RingBuffer ID: \"%s\" does not exist!\n", call_id.c_str());
return 0;
}
int a;
ost::MutexLock guard (_mutex);

View File

@ -22,6 +22,7 @@
#define __MAIN_BUFFER__
#include <map>
#include <set>
#include <cc++/thread.h> // for ost::Mutex
#include "../global.h"
@ -30,6 +31,8 @@
typedef std::map<CallID, RingBuffer*> RingBufferMap;
typedef std::set<CallID> RingBufferIDSet;
#define default_id "default_id"
class MainBuffer {

View File

@ -170,5 +170,8 @@ void MainBufferTest::testGetPutData()
CPPUNIT_ASSERT(_mainbuffer.getData(&test_output, sizeof(int), 100, test_id) == sizeof(int));
CPPUNIT_ASSERT(test_input2 == test_output);
CPPUNIT_ASSERT(_mainbuffer.putData(&test_input2, sizeof(int), 100, false_id) == 0);
CPPUNIT_ASSERT(_mainbuffer.getData(&test_input2, sizeof(int), 100, false_id) == 0);
_mainbuffer.removeRingBuffer(test_id);
}