2 #include "data_container.h"
4 using namespace Netspecters::KernelPlus::DataContainer
;
6 CSegment::CSegment( CDataContainer
&parent
, const ST_SegmentInfor
&segment_create_infor
)
7 : m_virtual_border(segment_create_infor
.segment_base_offset
)
8 , m_io_notify_ptr( segment_create_infor
.io_notify_ptr
)
9 , m_segment_buffer_type( segment_create_infor
.segment_buffer_type
)
11 , m_base_offset( m_virtual_border
)
12 , m_border( segment_create_infor
.segment_border
)
14 /* 成功建立段后,必须增加数据容器的引用计数 */
15 parent
.addReference();
18 CFile
&CSegment::get_data_file()
20 return m_parent
.m_data_file
;
23 void CSegment::getSegmentInformation( ST_SegmentInfor
&segment_infor
)
25 segment_infor
.segment_base_offset
= m_base_offset
;
26 segment_infor
.segment_border
= m_border
;
27 segment_infor
.io_notify_ptr
= m_io_notify_ptr
;
30 int CSegment::io( CFile::ST_ListIOItem::ENM_IOType io_type
, void *data_buffer
, size_t data_size
, off_t offset
, long io_tag
, bool force_sync
)
34 CFile::ST_ListIOItem list_io_item
;
35 list_io_item
.io_type
= io_type
;
36 list_io_item
.data_ptr
= data_buffer
;
37 list_io_item
.data_size
= data_size
;
38 list_io_item
.offset
= offset
;
39 list_io_item
.io_key
= ( uintptr_t )this;
40 list_io_item
.io_tag
= ( uintptr_t )io_tag
;
41 return m_parent
.m_data_file
.list_io( &list_io_item
, 1, force_sync
);
47 m_parent
.releaseReference();
50 void CSegment::onFileIOCallback( CFile
*file_ptr
, const CFile::ST_ListIOItem
&list_io_item
)
52 CSegment
*segment_ptr
= ( CSegment
* )( list_io_item
.io_key
);
53 if( segment_ptr
->m_io_notify_ptr
)
55 switch( list_io_item
.io_type
)
57 case CFile::ST_ListIOItem::ioRead
:
58 segment_ptr
->m_io_notify_ptr
->onIORealRead( list_io_item
.data_ptr
, list_io_item
.data_size
, list_io_item
.io_tag
);
60 case CFile::ST_ListIOItem::ioWrite
:
61 segment_ptr
->m_io_notify_ptr
->onIORealWrite( list_io_item
.data_ptr
, list_io_item
.data_size
, list_io_item
.io_tag
);
65 segment_ptr
->releaseReference();