webengine/device/src/DeviceLiwInterface.cpp
changeset 10 a359256acfc6
parent 0 dd21522fd290
child 48 79859ed3eea9
equal deleted inserted replaced
5:10e98eab6f85 10:a359256acfc6
    28 #include "DeviceLiwPeer.h"
    28 #include "DeviceLiwPeer.h"
    29 
    29 
    30 using namespace KJS;
    30 using namespace KJS;
    31 
    31 
    32 const ClassInfo DeviceLiwInterface::info = { "DeviceLiwInterface", 0, 0, 0 };
    32 const ClassInfo DeviceLiwInterface::info = { "DeviceLiwInterface", 0, 0, 0 };
    33 const TInt INIT_RST_ARRAY_SIZE = 10;   // initial result object array
       
    34 
    33 
    35 // ============================= LOCAL FUNCTIONS ===============================
    34 // ============================= LOCAL FUNCTIONS ===============================
    36 /*
    35 /*
    37 @begin DeviceLiwInterfaceTable 1
    36 @begin DeviceLiwInterfaceTable 1
    38     close DeviceLiwInterface::close DontDelete|Function 0
    37     close DeviceLiwInterface::close DontDelete|Function 0
    50     ExecState* exec,
    49     ExecState* exec,
    51     MDeviceBinding* deviceBinding,
    50     MDeviceBinding* deviceBinding,
    52     MDevicePeer* devicePeer )
    51     MDevicePeer* devicePeer )
    53     : JSObject( exec->lexicalInterpreter()->builtinObjectPrototype() )
    52     : JSObject( exec->lexicalInterpreter()->builtinObjectPrototype() )
    54     {
    53     {
    55         m_privateData = new DeviceLiwInterfacePrivate(deviceBinding, devicePeer);
    54     m_valid = EFalse;
    56         if (!m_privateData || !m_privateData->m_devicePeer )
    55     m_privateData = NULL;
    57             m_valid = false;
    56     if ( deviceBinding && devicePeer)
    58         else 
    57         {
    59             m_valid = true;           
    58         m_privateData = new DeviceLiwInterfacePrivate(this, deviceBinding, devicePeer);
       
    59         if ( m_privateData )
       
    60             m_valid = ETrue;
       
    61         }
    60     }
    62     }
    61 
    63 
    62 // ----------------------------------------------------------------------------
    64 // ----------------------------------------------------------------------------
    63 // DeviceLiwInterface::~DeviceLiwInterface
    65 // DeviceLiwInterface::~DeviceLiwInterface
    64 //
    66 //
    65 // ----------------------------------------------------------------------------
    67 // ----------------------------------------------------------------------------
    66 //
    68 //
    67 DeviceLiwInterface::~DeviceLiwInterface()
    69 DeviceLiwInterface::~DeviceLiwInterface()
    68     {
    70     {
    69     delete m_privateData;
    71     Close();
    70     }
    72     }
    71 
    73 
    72 // ----------------------------------------------------------------------------
    74 // ----------------------------------------------------------------------------
    73 // DeviceLiwInterface::Close
    75 // DeviceLiwInterface::Close
    74 //
    76 //
    75 // ----------------------------------------------------------------------------
    77 // ----------------------------------------------------------------------------
    76 //
    78 //
    77 void DeviceLiwInterface::Close(ExecState* exec)
    79 void DeviceLiwInterface::Close()
    78     {
    80     {
    79     if(!m_valid)
    81     if(!m_valid)
    80         return;
    82         return;
    81     
    83     
    82     // need exec to close other jsobject
    84     m_valid = EFalse;
    83     m_privateData->m_exec = exec;
       
    84     delete m_privateData;
    85     delete m_privateData;
    85     m_privateData = NULL;
    86     m_privateData = NULL;
    86     m_valid = false;   
       
    87     }
    87     }
    88 
    88 
    89 // ----------------------------------------------------------------------------
    89 // ----------------------------------------------------------------------------
    90 // DeviceLiwInterface::getOwnPropertySlot
    90 // DeviceLiwInterface::getOwnPropertySlot
    91 //
    91 //
   209 
   209 
   210 // ---------------------------------------------------------------------------
   210 // ---------------------------------------------------------------------------
   211 // DeviceLiwInterfacePrivate constructor
   211 // DeviceLiwInterfacePrivate constructor
   212 //
   212 //
   213 // ---------------------------------------------------------------------------
   213 // ---------------------------------------------------------------------------
   214 DeviceLiwInterfacePrivate::DeviceLiwInterfacePrivate(MDeviceBinding* deviceBinding, MDevicePeer* devicePeer)
   214 DeviceLiwInterfacePrivate::DeviceLiwInterfacePrivate(DeviceLiwInterface* jsobj, MDeviceBinding* deviceBinding, MDevicePeer* devicePeer)
   215     {
   215     {
   216     TRAP_IGNORE(
   216     TRAP_IGNORE(
   217         m_resultObjArray = new RPointerArray<DeviceLiwResult>( INIT_RST_ARRAY_SIZE );
       
   218         m_deviceBinding = deviceBinding;    
   217         m_deviceBinding = deviceBinding;    
   219         m_devicePeer = devicePeer;
   218         m_devicePeer = devicePeer;
   220         m_exec = NULL;
   219         m_exec = NULL;
       
   220         m_jsobj = jsobj;
   221         )
   221         )
   222     }
   222     }
   223 
   223 
   224 // ---------------------------------------------------------------------------
   224 // ---------------------------------------------------------------------------
   225 // DevicePrivate Close
   225 // DevicePrivate destructor
   226 //
   226 //
   227 // ---------------------------------------------------------------------------
   227 // ---------------------------------------------------------------------------
   228 void DeviceLiwInterfacePrivate::Close()
   228 DeviceLiwInterfacePrivate:: ~DeviceLiwInterfacePrivate()
   229     {    
   229     {
   230     if ( m_resultObjArray && m_exec)
   230     // invalid the DeviceLiwInterface
   231         {
   231     if (m_jsobj)
   232         // close all the result objects created for this device
   232         m_jsobj->m_valid = EFalse; 
   233         for (int i = 0; i < m_resultObjArray->Count(); i++)
   233        
   234             {
       
   235             (*m_resultObjArray)[i]->Close( m_exec, true );
       
   236             }
       
   237         m_resultObjArray->Close();
       
   238         delete m_resultObjArray;
       
   239         m_resultObjArray = NULL;
       
   240         }
       
   241         
       
   242     m_deviceBinding = NULL;
       
   243     m_exec = NULL;
       
   244     
       
   245     delete m_devicePeer;
   234     delete m_devicePeer;
   246     m_devicePeer = NULL;
   235     m_devicePeer = NULL;
   247     }
   236     }
   248 
   237 
   249 // ----------------------------------------------------------------------------
   238 // ----------------------------------------------------------------------------
   302         // the close function cann't be called in the callback function
   291         // the close function cann't be called in the callback function
   303         if(sapiif->IsRunningCallBack())
   292         if(sapiif->IsRunningCallBack())
   304             {
   293             {
   305             return throwError(exec, GeneralError, "Can not close interface object in callback function.");
   294             return throwError(exec, GeneralError, "Can not close interface object in callback function.");
   306             }
   295             }
   307         sapiif->Close(exec);
   296         sapiif->Close();
   308         return ret;
   297         return ret;
   309         }
   298         }
   310 
   299 
   311     ret = sapiif->InvokeOp( exec, m_funcName, aArgs );
   300     ret = sapiif->InvokeOp( exec, m_funcName, aArgs );
   312     
   301     
   313     if(ret->isObject() && (static_cast<JSObject*> (ret))->inherits( &KJS::DeviceLiwResult::info ))
   302     if(ret->isObject() && (static_cast<JSObject*> (ret))->inherits( &KJS::DeviceLiwResult::info ))
   314     {
   303     {
   315         // insert into jsobject array
   304         // insert into jsobject array
   316         sapiif->m_privateData->m_resultObjArray->Append(static_cast<DeviceLiwResult*> (ret));
   305         DevicePrivateBase* ifData = sapiif->getInterfaceData();
       
   306         DevicePrivateBase* retData =(static_cast<DeviceLiwResult*> (ret))->getResultData();
       
   307         retData->SetParent( ifData ); 
       
   308         ifData->AddChild( retData );
   317         if ( aArgs.size() > 1 )
   309         if ( aArgs.size() > 1 )
   318         {
   310         {
   319             bool ok;
   311             bool ok;
   320             TInt32 err; // check error code before extract transaction id
   312             TInt32 err; // check error code before extract transaction id
   321             err = ret->getObject()->get(exec, Identifier("ErrorCode"))->toInt32( exec, ok );
   313             err = ret->getObject()->get(exec, Identifier("ErrorCode"))->toInt32( exec, ok );