Company

Products

Services

Partners

Media

 

 

 

Home

Empress Markets

News & Events


Presentations

Press Releases

Product Profile

Success Stories

Technical News


White Papers

Join Mailing List

For More Info

           

    Empress Technical News – July 2009

    Empress API Cancel Functionality–
    Allows Fast Interactive Application Response

     

    Introduction

    Empress Ultra Embedded 10.20 offers many useful features for application developers. One of those features is the Cancel Functionality for Empress C/C++ Kernel Level API mr routines

    Empress Cancel Functionality

    How many times you found yourself in the situation when you had just started an interactive database task and realized it was taking too long to finish? How many times have you found yourself in the situation where you selected and sorted 20GB of Wikipedia data on a PDA without the right index and were waiting forever? How many times you found yourself in the situation when you invoked the wrong task by accident and could not stop it unless you pressed “FACTORY RESET”? All those situations can be under your control by using the new Empress Cancel Functionality.

    Empress Ultra Embedded V10.20 Cancel Functionality powers-up application developers to implement an effective interactive response for their real-time applications.

    All Empress Kernel Level API mr routines are synchronous in   After an application calls a mr routine, it has to wait until the Empress database engine completes all internal operations in regards to that specific routine. Then the question arises: how one can cancel a synchronous processing of any mr routine?

    Let’s assume that an application performs database tasks using Empress routines API   in one thread of execution – we will call this thread a worker thread. Empress new Cancel Functionality utilizes another thread of execution to check   routine executing in the worker thread and cancel its operation.

    The Cancel Functionality has been developed as an additional set of Empress C/C++ Kernel Level API mr routines

    Empress Cancel Functionality mr C API

    The Empress cancel functionality is developed via the following set of additional Empress C/C++ Kernel Level API – mr routines:

    mrenableconn()- turn off Cancel flag for that task
    mrdisableconn()-
    turn on Cancel flag for that task
    mrgetdefaultconn()-
    get info on mr task to set Cancel flag above

    Example Pseudo Code Using Cancel Functionality

    In the following pseudo code example cancel_db_task starts two threads, a worker thread where all database tasks are performed and a main thread used for canceling mr routines in the worker thread. Cancel activity is triggered by invoking the routine mrdisableconn().

    The pseudo code example cancel_db_task is as follows:

    /**** cancel_db_task ****/
    Main(UI) Thread:

    ..
    void
    * mrconnection = NULL
    Loop_on_UI_events()
    {

                     
    if (Button_Start_Pressed)
                     
    {
                                     
    if (Worker_Thread_Not_Created)
                                                           
    Create_Worker_Thread()
                                       
                                       
    if (mrconnection != NULL)
                                                           
    mrenableconn(mrconnection)
                                       
    Wake_Up_Worker_Thread()
                     
    }
                     
    if (Button_Cancel_Pressed)
                     
    {
                                       
    cancelThread = TRUE
                                       
    mrdisableconn(mrconnection)
                     
    }
                     
    if (Button_Exit_Pressed)
                     
    {
                                       
    mrdisableconn(mrconnection)
                                       
    cancelThread = TRUE
                                       
    Set_Kill_Thread()
                                       
    Wake_Up_Worker_Thread()
                     
    }
    }

    int
    Worker_Thread_Func():
    {

                     
    mstask_hdr      mtask
                     
    void*  mr = NULL
                     
    void*  mra = NULL
                     
    void*  mrr = NULL
                     
    void*  g = NULL
                     
    ....
                     
    if (!mstask_init_set_task (& task))
                                       
    goto cleanup
                     
    if (!msinit())
                                       
    goto cleanup
                     
    mrconnection = mrgetdefaultconn
                     
    mr = mrmktmpview(" db" , " select id, name from big_table" )
                     
    if (mr == NULL)
                     
    {
                                       
    goto cleanup
                     
    }
                     
    mrr = mrmkrec(mr)
                     
    if (mrr == NULL)
                                       
    goto cleanup
                     
    mra = mrngeta(mr, " name" )
                     
    if (mra == NULL)
                                       
    goto cleanup
                     
    Loop()
                     
    {
                                       
    Wait_for_Wakeup()
                                       
    Enable_Cancel_Button()
                                       
    if (Kill_Thread)
                                                           
    break
                                       
    g = mrsrtbegin(0, , 0, mrr, 0, mra, 0)
                                       
    if (cancelThread || mroperr == MSMR_ERR_CONN_DISABLED)
                                                           
    continue
                                       
    else if (g == NULL)
                                                           
    goto cleanup
                                       
    while (TRUE)
                                       
    {
                                                           
    if (cancelThread)
                                                                             
    break
                                                           
    i = mrget(g)
                                                           
    if (cancelThread || mroperr == SMR_ERR_CONN_DISABLED)
                                                                             
    break
     

                                                           
    if (i != 1)
                                                                             
    break
                                                           
    value = mrgetvs(mrr, mra)
                                                           
    if (cancelThread || mroperr == SMR_ERR_CONN_DISABLED)
                                                                             
    break
                                                           
    if (value == (void*)-1)
                                                                             
    goto cleanup
                                                           
    process_valule()
                                       
    }
                                       
    if (g != NULL)
                                       
    {
                                                           
    disable_cancel_button()
                                                           
    mrenableconn(mrconnection)
                                                           
    mrgetend(g)
                                                           
    g = NULL
                                                           
    enable_cancel_button()
                                       
    }
                     
    }
    cleanup:

                     
    /* Prevent cleanup code from being canceled */
                     
    Disable_Cancel_Button()
                     
    /* Re-enable MR connection to execute cleanup code */
                     
    if (mrconnection != NULL)
                                       
    mrenableconn(mrconnection)
                     
    if (mrr)
                                       
    mrfrrec(mrr)
                     
    if (mr)
                                       
    mrclose(mr)
                     
    if (g)
                                       
    mrgetend(g)
                     
    msend()
                     
    mstask_end_task (& task)
                     
    mrconnection = 0
                     
    enable_cancel_button()
                     
    ....
    }
     

    Thediagram in the Fig 1 shows the simplified flow of activities in the pseudo code example

    Fig 1: Empress Cancel Functionality

     

    Instead of Summary

    Empress Cancel functionality can be  useful for developers of interactive applications.

    On the other hand, developers may find that Empress Timeout functionality may be more convenient for those applications that run without user interaction.

    It’s your choice!!!

    Empress Software Inc.
    www.empress.com

                       
                             
                         

Company
Information
GSA Contracts
Careers
Privacy Policy 
Contact US

Products
Empress RDBMS
Empress Servers
Empress API
Free Trial 
Empress iPad Apps
 

Services
Consulting
Mobile Apps Development
Technical Support

Training Courses
Empress Extreme  

Partners
Distributors
Business Alliances
Partner Programs  
GSA Program
Distributors Program

Media 
Empress Markets
News and Events
Press releases
Technical News
Success Stories

        USA: 301-220-1919                 Canada & International:       905-513-8888         
Copyright © 2014           Empress Software Inc.           info@empress.com           Join Empress Mailing List