15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <qtms.h> |
18 #include <qtms.h> |
19 #include <tmsbuffer.h> |
19 #include <tmsbuffer.h> |
|
20 #include "tmsutility.h" |
20 #include "qtmsmembuffer.h" |
21 #include "qtmsmembuffer.h" |
21 #include "tmsutility.h" |
|
22 |
22 |
23 using namespace QTMS; |
23 using namespace QTMS; |
24 using namespace TMS; |
24 using namespace TMS; |
25 |
25 |
26 QTMSMemBuffer::QTMSMemBuffer() |
26 QTMSMemBuffer::QTMSMemBuffer() |
27 { |
27 { |
|
28 iTmsBuffer = NULL; |
|
29 iOwnsBuffer = FALSE; |
28 } |
30 } |
29 |
31 |
30 QTMSMemBuffer::~QTMSMemBuffer() |
32 QTMSMemBuffer::~QTMSMemBuffer() |
31 { |
33 { |
32 delete iBuffer; |
34 if (iOwnsBuffer) |
|
35 { |
|
36 free(iDataPtr); |
|
37 } |
33 } |
38 } |
34 |
39 |
35 gint QTMSMemBuffer::Create(guint size, QTMSBuffer*& qbuffer, |
40 gint QTMSMemBuffer::Create(QTMSBuffer*& buffer, TMS::TMSBuffer*& tmsbuffer) |
36 TMS::TMSBuffer*& tmsbuffer) |
|
37 { |
41 { |
|
42 gint ret(QTMS_RESULT_INSUFFICIENT_MEMORY); |
38 TRACE_PRN_FN_ENT; |
43 TRACE_PRN_FN_ENT; |
39 gint ret(TMS_RESULT_INSUFFICIENT_MEMORY); |
|
40 QTMSMemBuffer* self = new QTMSMemBuffer(); |
44 QTMSMemBuffer* self = new QTMSMemBuffer(); |
41 if (self) |
45 if (self) |
42 { |
46 { |
43 ret = self->PostConstruct(); |
47 self->iTmsBuffer = tmsbuffer; |
44 if (ret != TMS_RESULT_SUCCESS) |
48 tmsbuffer->GetDataPtr(self->iDataPtr); |
45 { |
49 tmsbuffer->GetDataSize(self->iBufferSize); |
46 delete self; |
50 tmsbuffer->GetTimeStamp(self->iTimeStamp); |
47 self = NULL; |
51 self->iOwnsBuffer = FALSE; |
48 } |
|
49 self->iBuffer = tmsbuffer; |
|
50 } |
52 } |
51 qbuffer = self; |
53 buffer = self; |
52 TRACE_PRN_FN_EXT; |
54 TRACE_PRN_FN_EXT; |
53 return ret; |
|
54 } |
|
55 |
|
56 gint QTMSMemBuffer::PostConstruct() |
|
57 { |
|
58 gint ret(TMS_RESULT_SUCCESS); |
|
59 return ret; |
55 return ret; |
60 } |
56 } |
61 |
57 |
62 gint QTMSMemBuffer::GetType(QTMSBufferType& buffertype) |
58 gint QTMSMemBuffer::GetType(QTMSBufferType& buffertype) |
63 { |
59 { |
64 gint ret(QTMS_RESULT_UNINITIALIZED_OBJECT); |
60 gint ret(TMS_RESULT_SUCCESS); |
65 if (iBuffer) |
61 buffertype = QTMS_BUFFER_MEMORY; |
66 { |
|
67 ret = iBuffer->GetType(buffertype); |
|
68 } |
|
69 return ret; |
62 return ret; |
70 } |
63 } |
71 |
64 |
72 /** |
65 /** |
73 * Gets the timestamp on the Buffer so that the framework can |
66 * Gets the timestamp on the Buffer so that the framework can |
77 * @param ts timestamp in microseconds |
70 * @param ts timestamp in microseconds |
78 * |
71 * |
79 */ |
72 */ |
80 gint QTMSMemBuffer::GetTimeStamp(guint64& ts) |
73 gint QTMSMemBuffer::GetTimeStamp(guint64& ts) |
81 { |
74 { |
82 gint ret(QTMS_RESULT_UNINITIALIZED_OBJECT); |
75 gint ret(QTMS_RESULT_SUCCESS); |
83 if (iBuffer) |
76 ts = iTimeStamp; |
84 { |
|
85 ret = iBuffer->GetTimeStamp(ts); |
|
86 } |
|
87 return ret; |
77 return ret; |
88 } |
78 } |
89 |
79 |
90 /** |
80 /** |
91 * Sets the timestamp on the Buffer so that the framework can |
81 * Sets the timestamp on the Buffer so that the framework can |
95 * @param ts timestamp in milliseconds |
85 * @param ts timestamp in milliseconds |
96 * |
86 * |
97 */ |
87 */ |
98 gint QTMSMemBuffer::SetTimeStamp(const guint64 ts) |
88 gint QTMSMemBuffer::SetTimeStamp(const guint64 ts) |
99 { |
89 { |
100 gint ret(QTMS_RESULT_UNINITIALIZED_OBJECT); |
90 gint ret(QTMS_RESULT_SUCCESS); |
101 if (iBuffer) |
91 iTimeStamp = ts; |
102 { |
92 ret = iTmsBuffer->SetTimeStamp(ts); |
103 ret = iBuffer->SetTimeStamp(ts); |
|
104 } |
|
105 return ret; |
93 return ret; |
106 } |
94 } |
107 |
95 |
108 /** |
96 /** |
109 * Gets the size of data in the buffer specified by the client. |
97 * Gets the size of data in the buffer specified by the client. |
127 * @param size size of data in bytes |
112 * @param size size of data in bytes |
128 * |
113 * |
129 */ |
114 */ |
130 gint QTMSMemBuffer::SetDataSize(const guint size) |
115 gint QTMSMemBuffer::SetDataSize(const guint size) |
131 { |
116 { |
132 gint ret(QTMS_RESULT_UNINITIALIZED_OBJECT); |
117 gint ret(QTMS_RESULT_SUCCESS); |
133 if (iBuffer) |
118 ret = iTmsBuffer->SetDataSize(size); |
134 { |
119 iBufferSize = size; //TODO: should realloc when new size > old size (?) |
135 ret = iBuffer->SetDataSize(size); |
|
136 } |
|
137 return ret; |
120 return ret; |
138 } |
121 } |
139 |
122 |
140 /** |
123 /** |
141 * Gets the pointer to the memory location associated with this |
124 * Gets the pointer to the memory location associated with this |