correct some logic error
[netspecters.git] / source / KernelLibrary / DataContainer / segment.cpp
blobb531616ca30624434f5eb50ac862d57d5a99b8e4
1 #include "segment.h"
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 )
10 , m_parent( parent )
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 )
32 addReference();
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 );
44 CSegment::~CSegment()
46 /* 减少数据容器的引用计数 */
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 );
59 break;
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 );
62 break;
65 segment_ptr->releaseReference();