blob: 2a2f21397f84147dd8ee9785aee70a7379cafc0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*******************************************************************************
* Copyright (C) ST-Ericsson SA 2011
* License terms: 3-clause BSD license
******************************************************************************/
#ifndef _BUFFER_H_
#define _BUFFER_H_
#include "t_bulk_protocol.h"
#include "MemMappedFile.h"
#include "Queue.h"
#include "Logger.h"
#ifdef _WIN32
#include "WinApiWrappers.h"
#else
#include "LinuxApiWrappers.h"
#endif
#include <string>
#include <vector>
struct TBulkVector {
uint8 *HeaderBuffer_p;
uint8 *Data_p;
uint64 Offset;
uint32 Length;
uint32 ChunkSize;
TBulkVector();
~TBulkVector();
};
struct TBulkFile {
TBulkFile();
~TBulkFile();
std::string strFileName;
std::vector<TBulkVector *> bulkVectors;
size_t refCount;
int iAllSessionsCompleted;
MemMappedFile *pMemMappedFile;
CCriticalSectionObject csBulkVectors;
};
class Buffers
{
public:
Buffers();
~Buffers();
void SetLogger(Logger *logger) {
logger_ = logger;
}
private:
//Member variables for Bulk Flash.
static std::vector<TBulkFile *> m_BulkFiles;
static CCriticalSectionObject csBulkFiles;
TBulkFile *m_BulkFile;
public:
ErrorCode_e Init();
void *Allocate(int Size);
ErrorCode_e Release(void *Buffer_p, int Size);
uint32 Available(int BufferSize);
void Deinit();
//Functions for Bulk Flash
int AllocateBulkFile(std::string strFile);
uint64 GetBulkFileLength();
int AllocateBulkVector(TL_BulkVectorList_t *BulkVector_p, uint32 iChunkSize, uint64 lOffset, uint32 iLength);
void ReleaseBulkVector(TL_BulkVectorList_t *BulkVector_p);
void ReleaseBulkFile();
static void ReleaseAllBulkFiles();
private:
uint32 buffersCount_;
Logger *logger_;
static const uint32 MAX_BUFFERS_COUNT;
void PrintF(const char *text, void *pVoid);
};
#endif // _BUFFER_H_
|