PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXSource
Storage class for reading data from the ISource interface(SFBSource storage).
#include <SFXSource.h.hpp>
class SFXSource : public SFXStorage;
SFMTYPEDEFCLASS(SFXSource)

Inherince diagram

 Inheritance diagram of SFXSourceClass

Collaboration diagram

 Collaboration diagram of SFXSourceClass

Description

Limitation

The stream for writing data cannot be obtained, and the function to move the position for reading is not supported.

How to use the SFXSource class

  1. Create the SFBSource instance and prepare the storage for reading data from the ISource interface. And then register the storage using the SFXSource::Open function.
  2. Get the input stream for reading data from the ISource interface using the SFXSource::GetStreamReader function.
  3. Read data from the input stream. Whether or not data is read using the callback function depends on the type of storage.
  4. After using the input stream, release resources by calling the SFXSource::Close function.

Example 494. Sample code for reading data from ISource interface

Void MyClass::UseSFXSource(Void)
{
    SFXSource source; 
    static ACharConst data[] = "test data"; // read data
    SFXAnsiString string;           // variable to read data from SFBSource storage
    SFXBinaryStreamReader reader;   // input stream for reading data from SFBSource storage
    SFBSourceUtilSmp util;
    SFBSourceSmp bs;

    // create from SFBSource storage from memory block
    util = SFBSourceUtil::NewInstance();
    util->SourceFromMemory(data, sizeof(data), null, null, &bs);

    // open SFBSource storage
    if (source.Open(bs) == SFERR_NO_ERROR) {

        // get input stream for reading data from SFBSource storage
        if (source.GetStreamReader(1024, &reader) == SFERR_NO_ERROR) {

            reader.Fetch();  // read data from SFBSource storage to input stream 
            reader >> string; // read data from input stream to string

            // display data to read from SFBSource storage on BREW Output Window
            TRACE("size = %d", string.GetLength());   // display string length: "size = 9"
            TRACE("read = %s", string.GetCString());  // display string: "read = test data"  

            reader.Release();  // release input stream
        }
        source.Close();  // close SFBSource storage
    }
    return;
}

Reference

SFBSource | SFBSourceUtil | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader

Member

Constructor/Destructor
SFXSource( Void )
Constructor of SFXSource class.
~SFXSource( Void )
Destructor of SFXSource class.
Public Functions
Void Cancel( Void )
Cancel the callback.
Void Close( Void )
Close the ISource interface used internally.
SFBSourceSmpConstRef GetSFBSource( Void )
Get the instance of SFBSource class used internally.
SFCError GetStreamReader( UInt32 size , SFXStreamReaderPtr result )
GetStreamReader( SFXStreamReaderPtr result )
Get the input stream for reading data from the ISource interface(SFBSource storage).
SFCError GetStreamWriter( UInt32 size , SFXStreamWriterPtr result )
GetStreamWriter( SFXStreamWriterPtr result )
[ This function cannot be used now. ]
SFCError Open( SFXMemoryConstRef memory )
Open( SFBAStreamSmpConstRef stream )
Open( SFBSourceSmpConstRef source )
Open( SFXTCPSocketConstRef socket )
Open( SFXFileConstRef file )
Open( SFXZIPDecoderConstRef zip )
Register the SFBSource storage.
SFCError Read( VoidPtr buffer , UInt32Ptr size )
Read data from the ISource interface(SFBSource storage) without using the input stream.
SFCError ScheduleRead( CallbackSPP spp , VoidPtr reference )
Register callback function and schedule to read data from the ISource interface(SFBSource storage).
SFCError ScheduleWrite( CallbackSPP spp , VoidPtr reference )
[ This function cannot be used now. ]
SFCError Write( VoidConstPtr buffer , UInt32Ptr size )
[ This function cannot be used now. ]
Types
CallbackSPP (inherits from SFXStorage)
The prototype of the callback function for the SFXStorage class.

SFXSource::SFXSource
Constructor of SFXSource class.
[ public, explicit ]
SFXSource(Void);

Description

The resource is not allocated.


SFXSource::~SFXSource
Destructor of SFXSource class.
[ public, virtual ]
virtual ~SFXSource(Void);

SFXSource::Cancel
Cancel the callback.
[ public, virtual ]
Void Cancel(Void);

Description

Cancel the callback functions registered in the instance of SFBSource class used internally.

Reference

SFXSource::Close


SFXSource::Close
Close the ISource interface used internally.
[ public ]
Void Close(Void);

Description

The registered callback functions are also canceled.

Reference

SFXSource::Cancel


SFXSource::GetSFBSource
Get the instance of SFBSource class used internally.
[ public, const ]
SFBSourceSmpConstRef GetSFBSource(Void);

SFXSource::GetStreamReader
Get the input stream for reading data from the ISource interface(SFBSource storage).
[ public, virtual ]
SFCError GetStreamReader(
    UInt32 size                 // buffer size
    SFXStreamReaderPtr result   // pointer to the input stream for reading data from the ISource interface(SFBSource storage)
);
[ public, virtual ]
SFCError GetStreamReader(
    SFXStreamReaderPtr result   // pointer to the input stream for reading data from the ISource interface(SFBSource storage)
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If SFBSource storage is not registered (SFXSource::Open function has not been called): SFERR_INVALID_STATE
  • If insufficient memory : SFERR_NO_MEMORY

Description

The buffer size of the input stream for reading data from the ISource interface(SFBSource storage) can be specified. Use the SFXBinaryStreamReader, SFXAnsiStringStreamReader, or SFXWideStringStreamReader class for the input stream properly according to the type of data to read.

Reference

SFXSource::GetStreamWriter | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader


SFXSource::GetStreamWriter
[ This function cannot be used now. ]
[ public, virtual ]
SFCError GetStreamWriter(
    UInt32 size                 // size
    SFXStreamWriterPtr result   // pointer to the output stream for writing data to the ISource interface(SFBSource storage)
);
[ public, virtual ]
SFCError GetStreamWriter(
    SFXStreamWriterPtr result   // pointer to the output stream for writing data to the ISource interface(SFBSource storage)
);

Description

SFERR_UNSUPPORTED is returned.

Reference

SFXSource::GetStreamReader


SFXSource::Open
Register the SFBSource storage.
[ public ]
SFCError Open(
    SFXMemoryConstRef memory   
);
[ public ]
SFCError Open(
    SFXZIPDecoderConstRef zip   
);
[ public ]
SFCError Open(
    SFXFileConstRef file   
);
[ public ]
SFCError Open(
    SFXTCPSocketConstRef socket   
);
[ public ]
SFCError Open(
    SFBSourceSmpConstRef source   
);
[ public ]
SFCError Open(
    SFBAStreamSmpConstRef stream   
);

Return value

  • Success : SFERR_NO_ERROR
  • If SFBSource storage has already been registered : SFERR_INVALID_STATE
  • If argument is null : SFERR_INVALID_PARAM
  • If insufficient memory : SFERR_NO_MEMORY
  • If failed : SFERR_FAILED

Reference

SFXSource::Close


SFXSource::Read
Read data from the ISource interface(SFBSource storage) without using the input stream.
[ public, virtual ]
SFCError Read(
    VoidPtr buffer   // buffer to read data from the ISource interface(SFBSource storage)
    UInt32Ptr size   // buffer sizee
);

Argument

buffer

Specify the buffer to read data from the ISource interface(SFBSource storage).

size

Specify the size of buffer when calling SFXSource::Read function. When the SFXMemory::Source function ends, the size of data that is actually read is stored.

Return value

  • Success : SFERR_NO_ERROR
  • If SFBSource storage is not registered (SFXSource::Open function has not been called): SFERR_INVALID_STATE
  • If the size argumentis null : SFERR_INVALID_PARAM
  • If necessary to retry : AEE_STREAM_WOULDBLOCK

Description

Before using the SFXSource::Read function, call the SFXSource::Open function and register the SFBSource storage.

Reference

SFXSource::Open | SFXSource::ScheduleRead


SFXSource::ScheduleRead
Register callback function and schedule to read data from the ISource interface(SFBSource storage).
[ public, virtual ]
SFCError ScheduleRead(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • Success : SFERR_NO_ERROR
  • If SFBSource storage is not registered (SFXSource::Open function has not been called), or callback function has already been registered : SFERR_INVALID_STATE

Description

The SFXFile::ScheduleRead function is used to register the callback function in which the SFXSource::Read function is used to read data from the ISource interface(SFBSource storage).

[Note] Note
When the return value of SFXSource::Read function is AEE_STREAM_WOULDBLOCK or there is still remaining data to read, register the callback function using the SFXSource::ScheduleRead function, and then schedule the SFXSource::Read function in the callback function again.

Reference

SFXSource::Read


SFXSource::ScheduleWrite
[ This function cannot be used now. ]
[ public, virtual ]
SFCError ScheduleWrite(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to the callback function
);

Description

SFERR_UNSUPPORTED is returned.


SFXSource::Write
[ This function cannot be used now. ]
[ public, virtual ]
SFCError Write(
    VoidConstPtr buffer   // data to write
    UInt32Ptr size        // size of data to write
);

Description

SFERR_UNSUPPORTED is returned.