![]() ![]() ![]()
|
SophiaFramework UNIVERSE 5.1 |
#include <SFCApplication.h.hpp>
class SFCApplication : public SFCInvoker;
SFMTYPEDEFCLASS(SFCApplication)


How to use
All application classes of SophiaFramework UNIVERSE inherit from SFCApplication.
![]() |
Note |
|---|---|
|
When an application class which inherits from SFCApplication directly is used, you cannot utilize the SFY responder system unless the necessary initialization of the SFY responder is performed. In general, in case of utilizing the SFY responder system, it is recommended to use an application class which inherits from SFYApplication, where the necessary initialization of the SFY responder is implemented in itself by default. For more details, see the description in Root. | |
Event Handling [General Processing Flow]
![]() |
Priority callback function |
|---|---|
For more details, see the description of the SFCApplication::RegisterBypass function. | |
The actual codes in SophiaFramework UNIVERSE are as follows:
Example 775. Event loop in the SFCApplication class
/*private */Bool SFCApplication::Invoke(SFXEventConstRef event)
{
Bool overload(false); // flag indicating whether or not to handle the event duplicately
Bool render(false); // flag indicating whether or not to redraw the full screen
Bool result(false); // it fas been succeeded if "true"
switch (event.GetType()) {
case SFEVT_APP_START:
case SFEVT_APP_RESUME:
// if SFEVT_APP_START or SFEVT_APP_RESUME event
render = true; // redraw the full screen
case SFEVT_APP_STOP:
case SFEVT_APP_SUSPEND:
// if SFEVT_APP_START, SFEVT_APP_RESUME, SFEVT_APP_STOP, or SFEVT_APP_SUSPEND event
overload = true; // handle the event duplicately
result = true; // always return "true"
break;
default:
break;
}
if (_bypass) { // if a priority callback function is registered
if (_spp != null) {
// call the priority callback function
if ((*_spp)(event, _reference)) {
result = true; // the event has been handled
}
if (!_bypass) { // if the priority callback function is unregistered
render = true; // redraw the full screen
}
}
}
if (render) { // if it is necessary to redraw the full screen
// redraw the full screen
if (HandleRender(event)) {
result = true; // the full screen has been redrawn
}
}
if (!result || overload) {
// if the event has not been handled by the priority callback function
// or it is one of SFEVT_APP_START / SFEVT_APP_RESUME / SFEVT_APP_STOP / SFEVT_APP_SUSPEND events
// handle the event
if (HandleEvent(event)) {
result = true; // the event has been handled
}
}
return result;
}// SFCApplication::Invoke //
![]() |
Change of the function name [to be planned] |
|---|---|
In the near future, the function name of "SFCApplication::Invoke(SFXEventConstRef event)" is planned to be changed. Therefore, see only the content in the above code. | |
Virtual Functions
Table 192. Virtual function name and its default behaviour
| Virtual function name | Default behaviour | Override |
|---|---|---|
| SFCApplication::HandleEvent | - | Optional |
| SFCApplication::HandleRender | If no priority callback function is registered, this function will fill the full screen in white and return "true". Otherwise it will return "false" only without redrawing the screen. *1 | Optional |
| SFCApplication::HandleError | - | Optional |
![]() |
NOTE |
|---|---|
*1. Boot up the SFCApplication::HandleError function when the fatal error such as memory insufficiency occurs. | |
Make a user-defined application class
The code necessary to make a user-defined application class is as follows:
Example 776. Declaration
SFMTYPEDEFCLASS(USRApplication)
class USRApplication: public SFCApplication {
SFMSEALCOPY(USRApplication)
public:
static SFCInvokerPtr Factory(Void);
private:
explicit USRApplication(Void) static_throws;
virtual ~USRApplication(Void);
virtual Bool HandleEvent(SFXEventConstRef event); // event handler[optional]
virtual Bool HandleRender(SFXEventConstRef event); // full screen redrawing handler[optional]
virtual Bool HandleError(SFXEventConstRef event, SFCError error); // error handler[optional]
};
Example 777. Implementation
// boot loader: function first executed in BREW applet SFCApplet::FactorySPP SFCApplet::Boot(AEECLSID id, SFXAnsiStringPtr license) { // here place the license code *license = "heap://"; return (id == AEECLSID_USRAPPLICATION) ? (&USRApplication::Factory): (null); } // factory function to create instance of user-defined application class SFCInvokerPtr USRApplication::Factory(Void) { return::new USRApplication; } // constructor USRApplication::USRApplication(Void) static_throws { if (static_try()) { // here describe the initialization } } // destructor USRApplication::~USRApplication(Void) { // here describe the finalization } // event handler[optional] Bool USRApplication::HandleEvent(SFXEventConstRef event) { Bool result(false); // here describe various event handling return result; // return "true" if event has been handled, otherwise return "false" } // full screen redrawing handler[optional] Bool USRApplication::HandleRender(SFXEventConstRef event) { // here describe full screen redrawing when an applet starts, resumes, or return from the native BREW text input SFXGraphicsPtr graphics; Bool result(false); if (IsRenderable()) { // if screen can be redrawn (i.e., if no priority callback function is registered) // get SFXGraphics instance graphics = SFXGraphics::GetInstance(); if (graphics != null) { // fill device screen region in white // get device screen region with SFXGraphics::GetDeviceRectangle() // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) represents white color graphics->ClearRectangle(graphics->GetDeviceRectangle(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); // here describe other full screen redrawing // must update device screen region in case of applet without GUI framework graphics->Update(); result = true; // set result to "true" because device screen region has been redrawn } // if SFXGraphics instance cannot be gotten, call HandleError() else if (HandleError(event, SFERR_FAILED)) { result = true; // set result to "true" because error has been handled } } return result; // return "true" if device screen region has been redrawn or error has been handled, otherwise return "false" } // error handler[optional] Bool USRApplication::HandleError(SFXEventConstRef event, SFCError error) { Bool result(false); // here describe error handling when fatal error occurs in HandleEvent() or HandleRender() return result; // return "true" if error has been handled, otherwise return "false" }
![]() |
The return statement in the constructor or destructor |
|---|---|
|
In general, the return statement should not be written in the constructor and destructor with C++. The bug has been confirmed in GCC. It is that compiler will freeze if the return statement is written in the constructor or destructor under some particular inheritance relationship. | |
SFYApplication | SFRApplication | SFCApplication::HandleEvent | SFCApplication::HandleRender | SFCApplication::RegisterBypass | SFCApplication::UnregisterBypass | SFCApplication::IsRenderable | BREW API ITextCtl | BREW-Defined Event | SFY Responder | Renderer | Distributer
| Constructor/Destructor |
|---|
|
SFCApplication( Void ) Constructor of the SFCApplication class.
|
|
~SFCApplication( Void ) Destructor of the SFCApplication class.
|
| Public Functions | |
|---|---|
| static AEECLSID |
GetClassID( Void ) Get the ClassID of this BREW applet.
|
| static SFCApplicationPtr |
GetInstance( Void ) Get the instance of this application.
|
| Bool |
Invoke(
SFXEventConstRef event
) [DEPRECATED]This is a virtual function that will be called when an event dispatched from the BREW environment needs to be handled.
|
| Bool |
IsRenderable( Void ) Check whether or not the screen can be drawn.
|
| SFCError |
RegisterBypass(
CallbackSPP spp
, VoidPtr reference
) Register the priority callback function.
|
| static SFCError |
Terminate(
Bool idle = false
) Terminate this application.
|
| Void |
UnregisterBypass(
CallbackSPP spp
, VoidPtr reference
) Unregister the priority callback function.
|
| Protected Functions | |
|---|---|
| Bool |
HandleError(
SFXEventConstRef event
, SFCError error
) This is a virtual function that will be called when the fatal error occurs.
|
| Bool |
HandleEvent(
SFXEventConstRef event
) This is a virtual function that will be called when an event dispatched from the BREW environment needs to be handled.
|
| Bool |
HandleRender(
SFXEventConstRef event
) This is a virtual function that will be called when the full screen needs to be redrawn.
|
[ protected, explicit ] SFCApplication(Void);
This constructor performs the initializations as follows:
![]() |
Priority callback function |
|---|---|
For more details, see the description of the SFCApplication::RegisterBypass function. | |
SFCApplication | SFCApplication::RegisterBypass | Event Loop
[ protected, virtual ] ~SFCApplication(Void);
[ public, static ] AEECLSID GetClassID(Void);
[ public, static ] SFCApplicationPtr GetInstance(Void);
![]() |
Note |
|---|---|
|
The SFCApplication::GetInstance function calls the GETAPPINSTANCE function of BREW API internally Therefore, when the return value of GETAPPINSTANCE function is null, that of SFCApplication::GetInstance function is also null. | |
[ protected, virtual ] Bool HandleError( SFXEventConstRef event // event SFCError error // error value );
SFCApplication::HandleError a virtual function that will be called when the fatal error such as insufficient memory during the bootup of the distributer or the renderer occurs.
If the error is handled, "true" will be returned. Otherwise, "false" will be returned.
The default implementation does nothing but returns "false".
![]() |
Note |
|---|---|
|
Though this function return "true" when an event is handled. Otherwise "false" will be returned. You cannot prospect correctly whether or not processing will be done normally because it is an fatal error. In principle, the procedure to stop the applet will be described. | |
Implementation of the SFCApplication::HandleError function is as follows:
// virtual function that will be called when the fatal error occurs
/*protected virtual */Bool SFCApplication::HandleError(SFXEventConstRef /*event*/, SFCError /*error*/)
{
return false;
}// SFCApplication::HandleError //
SFCApplication::HandleEvent | SFCApplication::HandleRender | Renderer | Distributer
[ protected, virtual ] Bool HandleEvent( SFXEventConstRef event // event );
SFCApplication::HandleEvent is a virtual function that will be called when an event dispatched from the BREW environment(BREW-defined event) needs to be handled.
If the event is handled, "true" will be returned. Otherwise, "false" will be returned.
The default implementation does nothing but returns "false".
You can override this virtual function for your own processing.
Implementation of the SFCApplication::HandleEvent function is as follows:
// virtual function that will be called when an event dispatched from the BREW environment needs to be handled /*protected virtual */Bool SFCApplication::HandleEvent(SFXEventConstRef /*event*/) { // here describe the handling of the event dispatched from the BREW environment return false; }// SFCApplication::HandleEvent //
[ protected, virtual ] Bool HandleRender( SFXEventConstRef event // event );
SFCApplication::HandleRender is a virtual function that will be called when the full screen needs to be redrawn.
If the full screen is redrawn, "true" will be returned. Otherwise, "false" will be returned.
In the default implementation, if no priority callback function is registered, this function will fill the full screen in white and return "true". Otherwise it will return "false" only without redrawing the screen.
![]() |
When the HandleRender() function is called |
|---|---|
|
When an applet starts, an applet resumes, the priority callback function handles an event, or the priority callback function is unregistered such as at the retrun from the native text input, the full screen needs to be redrawn. The SFCApplication::HandleRender function is automatically called at these times. | |
![]() |
Priority callback function |
|---|---|
For more details, see the description of the SFCApplication::RegisterBypass function. | |
![]() |
Normal drawing processing |
|---|---|
Normal drawing processing has nothing to do with the SFCApplication::HandleRender function. This processing can be specified anywhere in the program. | |
You can override this virtual function for your own processing.
Implementation of the SFCApplication::HandleRender function is as follows:
// virtual function that will be called when the full screen needs to be redrawn /*protected virtual */Bool SFCApplication::HandleRender(SFXEventConstRef event) { // here describe full screen redrawing when an applet starts, resumes, or returns from the native BREW text input SFXGraphicsPtr graphics; Bool result(false); if (IsRenderable()) { // if screen can be redrawn (i.e., if no priority callback function is registered) // get SFXGraphics instance if ((graphics = SFXGraphics::GetInstance()) != null) { // fill device screen region in white // get device screen region with SFXGraphics::GetDeviceRectangle() // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) represents white color graphics->ClearRectangle(graphics->GetDeviceRectangle(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); // call SFXGraphics::Update() to redraw device screen region // * device screen region will not be redrawn or updated if line below is NOT described graphics->Update(); result = true; // set result to "true" because device screen region is redrawn } // if SFXGraphics instance cannot be gotten, call HandleError() else if (HandleError(event, SFERR_FAILED)) { result = true; // set result to "true" because error has been handled } } return result; // return "true" if device screen region has been redrawn or error has been handled, otherwise return "false" }// SFCApplication::HandleRender //
Reference: SFXGraphics | SFXGraphics::GetInstance | SFXGraphics::GetDeviceRectangle | SFXGraphics::ClearRectangle | SFXGraphics::Update | SFCApplication::IsRenderable | SFCApplication::HandleError | SFYApplication::HandleRender
SFCApplication::RegisterBypass | SFCApplication::UnregisterBypass | BREW API ITextCtl | Renderer | Distributer | BREW-Defined Event
[ public, virtual ] Bool Invoke( SFXEventConstRef event // event );
![]() |
Caution |
|---|---|
| Since this function is deprecated, use the SFCApplication::HandleEvent function. | |
[ public, const ] Bool IsRenderable(Void);
If a priority callback function to handle the standard BREW control such as a native text input control( BREW API ITextCtl Interface) which will occupy the full screen is registered, the full screen will be occupied by this priority callback function. Therefore, any function other than this priority callback function must not draw the screen while it is registered.
SFCApplication::IsRenderable is the function to check this status.
![]() |
Priority callback function |
|---|---|
For more details, see the description of the SFCApplication::RegisterBypass function. | |
The below is the usage example in implemetation of the SFCApplication::HandleRender function.
// virtual function that will be called when the full screen needs to be redrawn /*protected virtual */Bool SFCApplication::HandleRender(SFXEventConstRef event) { SFXGraphicsPtr graphics; Bool result(false); if (IsRenderable()) { // if screen can be redrawn (i.e., if no priority callback function is registered) // get SFXGraphics instance if ((graphics = SFXGraphics::GetInstance()) != null) { // fill device screen region in white // get device screen region with SFXGraphics::GetDeviceRectangle() // SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00) represents white color graphics->ClearRectangle(graphics->GetDeviceRectangle(), SFXRGBColor(0xFF, 0xFF, 0xFF, 0x00)); // call SFXGraphics::Update() to redraw device screen region // * device screen region will not be redrawn or updated if line below is NOT described graphics->Update(); result = true; // set result to "true" because device screen region is redrawn } // If fails in getting SFXGraphics object, call HandleError() else if (HandleError(event, SFERR_FAILED)) { result = true; } } return result; }// SFCApplication::HandleRender //
Reference: SFXGraphics | SFXGraphics::GetInstance | SFXGraphics::GetDeviceRectangle | SFXGraphics::ClearRectangle | SFXGraphics::Update | SFCApplication::IsRenderable | SFCApplication::HandleError | SFYApplication::HandleRender
SFCApplication::RegisterBypass | BREW API ITextCtl | BREW-Defined Event | Renderer | Distributer
[ public ] SFCError RegisterBypass( CallbackSPP spp // priority callback function VoidPtr reference // user data );
SFCApplication::RegisterBypass is the function to register the priority callback function into the instance of an application class inheriting from SFCApplication.
Only one priority callback function can be registered into one instance of an application class inheriting from SFCApplication.
![]() |
Priority callback function |
|---|---|
|
For instance, when a standard BREW control such as the BREW API ITextCtl interface is running(or "active"), an event dispatched from the BREW environment(BREW-defined event) needs to be dispatched to this control first before the distributer or responders. The function that will handle the event first of all is called priority callback function. Event handling of the "active" BREW API ITextCtl interface will be performed inside this priority callback function. The priority callback function is registered with the SFCApplication::RegisterBypass function, and is unregistered with the SFCApplication::UnregisterBypass function. If a priority callback function is registered, the full screen will be occupied by this priority callback function. Therefore, it will be necessary to redraw the full screen when an event is handled by this priority callback function or priority callback function is unregistered with the SFCApplication::UnregisterBypass function. However, this redrawing will be done by the SFCApplication::HandleRender function, which will be called automatically. | |
The below is the usage example in implemetation of the SFXEditor::Open function.
/*public virtual*/SFCError SFXEditor::Open(SFXEditPropertyPtr property, CallbackSPP spp, VoidPtr reference)
{
static SFXRGBColor::AtomRecConst color[] = {
{{{0x00, 0xFF, 0xFF, 0xFF}}},
{{{0x00, 0x00, 0x00, 0x00}}}
};
SFBDisplaySmp display;
SFXWideString string;
SFXRectangle remember;
SFXRectangle rectangle;
UInt32 flag;
SFCError error(SFERR_NO_ERROR);
if (property != null) {
_property = property;
if ((display = SFBDisplay::GetInstance()) != null) {
display->GetClipRect(&remember);
display->SetClipRect(SFXRectangle::EmptyInstance());
if ((_menuctl = SFBMenuCtl::NewInstance(GetSFBMenuCtlClassID(), &error)) != null) {
if ((error = string.Set(ITEM_NAME)) == SFERR_NO_ERROR) {
if (_menuctl->AddItem(LABEL_OK, &string, reinterpret_cast<UInt32>(_menuctl.Get()))) {
if ((_textctl = SFBTextCtl::NewInstance(GetSFBTextCtlClassID(), &error)) != null) {
flag = _textctl->GetProperties();
flag |= TP_FRAME | TP_MULTILINE | TP_FIXSETRECT;
if (_property->GetPasswordMode()) {
flag |= TP_PASSWORD;
}
_textctl->SetProperties(flag);
rectangle.Set(SFXGrid::ZeroInstance(), SFXDevice().GetScreenSize());
rectangle.SubBottom(_menuctl->GetRect().GetHeight());
_textctl->SetRect(rectangle);
_textctl->SetSoftKeyMenu(_menuctl);
_textctl->SetMaxSize(_property->GetMaximumLength());
_textctl->SetInputMode(_property->GetInputMode());
if (_textctl->SetText(_property->GetText())) {
if ((error = RegisterBypass(XALLBACK_INTERNAL(OnBypass))) == SFERR_NO_ERROR) {
_spp = spp;
_reference = reference;
}
}
else {
error = SFERR_FAILED;
}
}
}
else {
error = SFERR_FAILED;
}
}
}
if (error != SFERR_NO_ERROR) {
Close();
}
display->SetClipRect(remember);
if (error == SFERR_NO_ERROR) {
display->SetColor(CLR_USER_TEXT, color[1]);
display->SetColor(CLR_USER_BACKGROUND, color[0]);
display->SetColor(CLR_USER_LINE, color[1]);
_textctl->SetActive(true);
_textctl->SetCursorPos(TC_CURSORSTART);
}
}
else {
error = SFERR_FAILED;
}
}
else {
error = SFERR_INVALID_PARAM;
}
return error;
}// SFXEditor::Open //
/*private */XALLBACK_IMPLEMENT_SFCAPPLICATION(SFXEditor, OnBypass, event)
{
SFXWideString string;
SFCError error;
Bool result(false);
result = _textctl->HandleEvent(event);
if (!result) {
#if defined TARGET_ENVIRONMENT_SIMULATOR
result = _menuctl->HandleEvent(event);
#endif
}
switch (event.GetType()) {
case SFEVT_APP_RESUME:
result = true;
break;
case SFEVT_APP_SUSPEND:
result = true;
break;
case SFEVT_KEY:
case SFEVT_KEY_PRESS:
case SFEVT_KEY_RELEASE:
#if TARGET_VERSION_LT(3, 0, 0)
case SFEVT_KEY_HELD:
#endif
result = true;
break;
case SFEVT_COMMAND:
if (!result) {
switch (event.GetP16()) {
case LABEL_OK:
if ((error = string.Set(_textctl->GetTextPtr())) == SFERR_NO_ERROR) {
if ((error = _property->SetText(string.Substring(0, _property->GetMaximumLength()))) == SFERR_NO_ERROR) {
_property->SetInputMode(_textctl->GetInputMode());
}
}
Close();
if (_spp != null) {
(*_spp)(error, _reference);
}
break;
default:
break;
}
result = true;
}
break;
default:
break;
}
return result;
}// XALLBACK_IMPLEMENT_SFCAPPLICATION(SFXEditor, OnBypass) //
SFCApplication::UnregisterBypass | SFXEditor::Open | SFCApplication::IsRenderable | BREW API ITextCtl | BREW-Defined Event | Renderer | Distributer | SFY Responder System
[ public, static ] SFCError Terminate( Bool idle = false // whether or not to terminate all BREW applets (this argument is effect only on a real device) );
The SFCApplication::Terminate function terminates the BREW applets that are currently active, and releases the memory allocated to the BREW applets from the heap.
If the idle argument is set to "true", all BREW applets will be terminated and the screen to wait for a phone call will appear.
If the idle argument is set to "false", only the currently active BREW applet will be terminated and the screen to select a BREW applet will appear.
For more details, see the description of BREW API ISHELL_CloseApplet in the BREW API reference.
![]() |
Finalization of the SFYApplication class |
|---|---|
|
When the Terminate() function of the SFYApplication calss is called, the SFCApplication::Terminate function inherited from the SFCApplication class will be executed. At this time, the finalization of the application class will be performed and its destructor, the SFYApplication::~SFYApplication function, will be called. In the SFYApplication::~SFYApplication function, the finalizations of all responders in the responder tree including the root will be performed. And the finalization of the renderer and the distributer which the application class contains internally. Concretely, in the SFYApplication::~SFYApplication function, the SFXResponderPointer::Release function of the root will be called first of all to release its smart pointer. This processing will make the reference count of the root "0", and the SFYResponder::Terminate function of the root will be called automatically to perform its finalization. Next, all responders in the responder tree will be disassembled into independent responders, whose reference counts will become "0". As a result, their SFYResponder::Terminate functions will be called to perform their finalizations too. At the end, the SFYRenderer::Terminate function and the SFYDistributer::Terminate function will be called in this order to perform the finalizations of the renderer and the distributer too. Reference: SFYApplication | Responder | Root | Responder Tree | Distributer | Renderer | SFYApplication::~SFYApplication | SFXResponderPointer::Release | SFYResponder::Terminate | SFYRenderer::Terminate | SFYDistributer::Terminate | |
BREW API ISHELL_CloseApplet | SFYApplication | SFYApplication::~SFYApplication | SFXResponderPointer::Release | SFYResponder::Terminate | SFYRenderer::Terminate | SFYDistributer::Terminate | SFY Responder | Root Responder | Responder Tree | Distributer | Renderer
[ public ] Void UnregisterBypass( CallbackSPP spp // priority callback function VoidPtr reference // user data );
SFCApplication::UnregisterBypass is the function to unregister the priority callback function from the instance of an application class inheriting from SFCApplication.
Only one priority callback function can be registered into one instance of an application class inheriting from SFCApplication.
![]() |
Priority callback function |
|---|---|
For more details, see the description of the SFCApplication::RegisterBypass function. | |
The below is the usage example in the implementation of the SFXEditor::Close function.
/*public */Void SFXEditor::Close(Void)
{
if (_textctl.control != null) {
if (_textctl.control->IsActive()) {
_textctl.control->SetActive(false);
}
}
if (_menuctl.control != null) {
if (_menuctl.control->IsActive()) {
_menuctl.control->SetActive(false);
}
}
if (_application != null) {
_application->UnregisterBypass(XALLBACK_INTERNAL(OnBypass));
}
_textctl.control.Release();
_menuctl.control.Release();
_application = null;
return;
}// SFXEditor::Close //
/*private */XALLBACK_IMPLEMENT_SFCAPPLICATION(SFXEditor, OnBypass, event)
{
SFXWideString string;
SFCError error;
Bool result(false);
...
// same with OnBypass function of usage example in the implementation of SFCApplication::RegisterBypass function
....
}// XALLBACK_IMPLEMENT_SFCAPPLICATION(SFXEditor, OnBypass) //
SFCApplication::RegisterBypass | SFXEditor::Close | BREW API ITextCtl | BREW-Defined Event | Renderer | Distributer
|
Copyright(c) 2002 - 2010 Sophia Cradle Incorporated All Rights Reserved. |
![]() ![]() ![]()
|