CN101826004A - Method for mandating functions by Applet - Google Patents

Method for mandating functions by Applet Download PDF

Info

Publication number
CN101826004A
CN101826004A CN200910046864A CN200910046864A CN101826004A CN 101826004 A CN101826004 A CN 101826004A CN 200910046864 A CN200910046864 A CN 200910046864A CN 200910046864 A CN200910046864 A CN 200910046864A CN 101826004 A CN101826004 A CN 101826004A
Authority
CN
China
Prior art keywords
applet
function
chained list
depositing
functions
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN200910046864A
Other languages
Chinese (zh)
Inventor
陈榕
宋世军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
KETAI CENTURY SCIENCE AND TECHNOLOGY Co Ltd SHANGHAI
Original Assignee
KETAI CENTURY SCIENCE AND TECHNOLOGY Co Ltd SHANGHAI
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by KETAI CENTURY SCIENCE AND TECHNOLOGY Co Ltd SHANGHAI filed Critical KETAI CENTURY SCIENCE AND TECHNOLOGY Co Ltd SHANGHAI
Priority to CN200910046864A priority Critical patent/CN101826004A/en
Publication of CN101826004A publication Critical patent/CN101826004A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention provides a method for mandating functions by Applet. The method comprises the following steps of: establishing a linked list object on a main thread of the Applet and realizing a mandatory function linked list on the linked list object; regetering functions required to be mandated; inserting pointers of the registered functions required to be mandated into the mandatory function linked list according to the handle of the Applet; when the operation of the main thread of the Applet is ended, obtaining the mandatory function linked list according to the handle of the Applet; and traversing the mandatory function linked list and calling all the mandated functions according to an order opposite to the time order for registering the functions. By utilizing the method for mandating the functions, the complexity and the coupling degree of a procedure can be reduced, and the relation between codes and all modules is simpler and clearer.

Description

The method of Applet depositing function
Technical field
The invention relates to a kind of when computer component is programmed the method for depositing function, refer in particular in method by the Applet depositing function by thread.
Background technology
When utilizing Applet to programme on the Elastos platform, may wish to obtain the notice that Applet finishes, do the work of a little resources cleanings in close to an end moment of withdrawing from of Applet, some signs, transmission message informing etc. perhaps need be set when Applet finishes.
Applet uses the Main method to enter the mouth as it, but the Main method is returned to withdraw from and is not represented that Applet withdraws from, and the message circulation that just enters Applet, Applet is still in operation, this is for the user who writes the Applet member, wants the resource of distributing in the cleaning Main method when Applet finishes the to withdraw from comparison difficulty that becomes, but also can be at Main the inside registration depositing function by thread, meeting invokes thread depositing function obtains the notice that Applet withdraws from whereby indirectly when the Main thread withdraws from.
But if certain DLL or submodule, it is unpredictable by which thread dispatching, or it is complicated to call level, and the way of depositing function is just inconvenient on the Main of Applet thread formula.
Summary of the invention
In view of above content, be necessary to provide a kind of method of Applet depositing function.
The method of this Applet depositing function comprises step: creating a chained list class object on the main thread of Applet and realize a depositing function chained list on this chained list class object; Registration needs the function of trustship; According to the handle of this Applet the pointer of the register function that needs trustship is inserted into above-mentioned depositing function chained list; When Applet main thread end of run, obtain the depositing function chained list according to this Applet handle; Travel through this depositing function chained list, and the reverse order of the order when registering according to function calls all functions in trust.
The method of Applet depositing function of the present invention can make the user that one or several depositing functions are set, these depositing functions are estimated in the moment that Applet finishes to be about to withdraw from and are called, the user can be provided with the code trustship arbitrarily in the Applet scope, when thread execution arrives Managed Code, corresponding record can be set on current Applet, when Applet withdraws from user's code, enter when preparing done state, can call the function of previous trustship automatically.Therefore, even if the programmer of certain submodule also needn't be concerned about the module of oneself can by which thread dispatching, when be called, can obtain control in the moment that Applet finishes as long as the Applet depositing function is set, be carried out the operation of expection.
This carries out member and the code that work such as state, preservation data were cleared up, were provided with to some resources for finishing this special occasion at Applet, " Applet depositing function " of the present invention can greatly make things convenient for the user, the complexity of minimizing program and the degree of coupling make the relation between code and each module simpler and clear.
Description of drawings
Fig. 1 is the process flow diagram of method of the Applet depositing function of preferred embodiment of the present invention.
Fig. 2 is the synoptic diagram that concerns between Applet Main thread of the present invention and chained list class object CAutoRun and the depositing function chained list.
Embodiment
As shown in Figure 1, be the process flow diagram of method of the Applet depositing function of preferred embodiment of the present invention.
Step S200 goes up chained list class object CAutoRun of establishment at the main thread (Main) of Applet, realizes a depositing function chained list on the chained list class object CAutoRun of this establishment.And on this Applet, keep the pointer to object of this chained list class object CAutoRun.This chained list class object CAutoRun is a class with chain table function, has the function of common chained list, such as: insert and traversal, it is used to manage function in trust.
For example realized the function of the last chained list class object CAutoRun of establishment of main thread (Main) at Applet with following one section program code AA:
Class CAutoRun//be used to manage function in trust
{......}
Applet TFoo{ // suppose in the Applet of a TFoo by name
Public:
......
CAutoRun m_autoRun; // its object that has defined a CAutoRun type is as one-tenth
The member
}
With reference to shown in Figure 2, wherein Main1 is the main thread of Applet, CAutoRun chained list class object 10 is the chained list class object CAutoRun that are used to manage function in trust that create on this Main1, and depositing function chained list 11 is depositing function chained lists realizing on this chained list class object CAutoRun.
Step S204, user call the CApplet::AtFinish registration and need function in trust.
Step S206, user obtain the handle of this Applet so that obtain described depositing function chained list 11.On the Elastos platform, all codes all run on each Applet respectively, characteristic based on Applet, all run on TLS (the Thread LocalStorage of the thread in the Applet, local storage of thread or thread local storage) on handles of in store Applet all, therefore, the user can obtain the handle of Applet at any time.
Step S208, according to the handle of the Applet that is obtained, the user is inserted into the pointer of the register function that needs trustship in the above-mentioned depositing function chained list 11 that obtains, and also is about to this function trustship of registering on the described CAutoRun chained list class object 10.
Program segment BB realizes function is inserted into function on the depositing function chained list below for example available:
ECode?CApplet::AtFinish(
/*[in]*/PThreadQuitRoutine?pEntry,
/*[in]*/PVoid?pUserData
{
CThread::GetTlsObject (TLS_Applet , ﹠amp; PApplet); // acquisition current thread
Affiliated Apple object
PHeader=﹠amp; PApplet->m_autoRun; // obtain the depositing function chained list by Applet
PHeader=->Insert (pEntry, pUserData); // insert one to the depositing function chained list
The depositing function member
Return?NOERROR;
}
Step S210 when Applet main thread end of run, obtains the Applet handle of current thread from TLS, thereby obtains the depositing function chained list.
Step S212 travels through this depositing function chained list, and the reverse order of the order when registering according to function calls all functions in trust.
For example available following one section program code segments CC realizes calling the function of function in trust:
ECode?CleanupList()
{
CThread::GetTlsObject (TLS_Applet , ﹠amp; PApplet); // obtain under the current thread
The Applet object
PThreadQuitRoutine pEntry; The variable of // definition depositing function pointer type
PVoid pUserData; The pointer of // definition User Defined context data
In the main thread of Applet, call this program code segments CC and can realize clearing up the trustship letter
The function of number chained list:
Ecode TFoo::AppletMainRoutine (PVoid pParam) //the Main function institute of Applet
The entrance function of the thread of operation, the i.e. main thread of Applet
{
......
Ecode ec=TFoo::Main (pParam); // execution user's Main function
... // omit pilot process leapt to and prepared Applet
Code
CleanupList (); The tabulation of // cleaning depositing function
......
}
// following code is used to travel through the trustship chained list, and calls function in trust one by one
PHeader=﹠amp; PApplet->m_autoRun; // obtain the depositing function chained list by Applet
PList=pHeader->Prev (); // oppositely travel through chained list
=pHeader) // traversal trustship chained list, and call depositing function
PList->GetCurrent (﹠amp; PEntry , ﹠amp; PUserData); // obtain the holder of chained list present node
The pipe function pointer
PEntry (pUserData); // call the execution depositing function by the depositing function pointer
PList=pList->Prev (); // continuation is the traversal chained list oppositely
}
The pure bundle of ... // call
}
The purposes and the advantage of this bright depositing function are described by one section program code below.
Void OnFinish (PVoid pUserData) // Applet trustship letter of realizing by the user
Number is called when being expected at the Applet end
{
Assert ((Int32) pUerData==0x1234; // expection pUserData==0x1234, otherwise in
assert
CThread::Sleep (1000, NULL); // current thread was slept for 1 second
CConsole::Writeline (" In OnFinish function... "); // print to screen to export
}
The Main function of ECode TApplet::Main (...) // certain Applet
{
CConsole::WriteLine (" Entered TApplet::Main... "); // print to screen to export
CApplet::AtFinish (﹠amp; Onfinish, (PVoid) 0x1234); // to current Applet registration holder
The pipe function
CConsole::WriteLine (" Leaving TApplet::Main... "); // print to screen to export
Return NOERROR_EXIT; // withdraw from personal code work and do not enter message circulation, prepare
Withdraw from Applet
}
ECode ElastosMain (...) //entrance function of Elastos platform program
{
IApplet*pApplet;
......
CConsole::WriteLine (" Before CApplet::Start () "); // print to screen to export
PApplet->Start (...); Applet of // operation
PApplet->WaitUntilFinished (INFINITE, NULL); // wait for, up to Applet
End is returned
CConsole::WriteLine (" After WaitUntilFinished () "); Print to screen output
Return NOERROR_EXIT; // directly quit a program
}
Screen?Out:
Befor?CApplet::Start()
Entered?TApplet::Main...
Leaving?TApplet::Main...
In?OnFinish?function...
After?WaitUntilFinished()
Can see from top code snippet, can when thread finishes, can call function in trust automatically to current Applet registration function in trust by the CApplet::AtFinish function.Simultaneously, the user also can register a plurality of depositing functions in an Applet, these depositing functions can be when Applet finishes to withdraw from according to the execution that is called of the reverse order of registration order.
From screen output as can be known, when Applet::Main returned NOERROR_EXIT, Applet did not finish immediately, but enters among the depositing function OnFinish, and after OnFinish finished, the WaitUntiFinished among the ElastosMain just returned.
Based on the Elastos platform, the programmer can be provided with one or several depositing functions by Appet depositing function of the present invention, these functions can be called in the moment that Applet finishes to be about to withdraw from, the user can be provided with trustship by arbitrary code in the Applet scope, when thread execution arrives Managed Code, can corresponding record be set on current Applet, withdraw from user's code as Applet, enter when preparing done state, can call the function of previous trustship automatically.Like this, even if the programmer of certain submodule also needn't be concerned about the module of oneself can by which thread dispatching, when be called, can obtain control in the moment that Applet finishes as long as the Applet depositing function is set, be carried out the operation of expection.And the mechanism that this trustship mechanism is provided as the Elastos operating platform, guarantee under any circumstance trustship to be set, and can be called, the function that makes member that different company realized and code can suppose own trustship is called when Applet finishes, and needn't be concerned about member and code moved thread, call details such as moment point, only need tell system which function need be called when Applet finishes by depositing function, system will finish other work automatically.
This carries out member and the code that work such as state, preservation data were cleared up, were provided with to some resources for finishing this special occasion at Applet, " Applet depositing function " can greatly make things convenient for the user, the complexity of minimizing program and the degree of coupling make the relation between code and each module simpler and clear.

Claims (6)

1. the method for an Applet depositing function is characterized in that, this method comprises:
Create a chained list class object on the main thread of Applet and on this chained list class object, realizing a depositing function chained list;
Registration needs function in trust;
According to the handle of this Applet the pointer of the register function that needs trustship is inserted into above-mentioned depositing function chained list;
When Applet main thread end of run, obtain the depositing function chained list according to this Applet handle;
Travel through this depositing function chained list, and the reverse order of the order when registering according to function calls all functions in trust.
2. the method for Applet depositing function as claimed in claim 1 is characterized in that, also comprises step before step is inserted into above-mentioned depositing function chained list according to the handle of this Applet with the pointer of the register function that needs trustship:
Obtain the handle of this Applet.
3. the method for Applet managed object as claimed in claim 2 is characterized in that, the handle of described Applet is kept on the TLS that runs on the thread in this Applet.
4. the method for Applet depositing function as claimed in claim 1 is characterized in that, described depositing function chained list is used to store the pointer of function in trust.
5. the method for Applet depositing function as claimed in claim 1 is characterized in that, the chained list class object of described establishment is used to manage function in trust.
6. the method for Applet depositing function as claimed in claim 1 is characterized in that, the chained list class object of described establishment is CAutoRun.
CN200910046864A 2009-03-02 2009-03-02 Method for mandating functions by Applet Pending CN101826004A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN200910046864A CN101826004A (en) 2009-03-02 2009-03-02 Method for mandating functions by Applet

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN200910046864A CN101826004A (en) 2009-03-02 2009-03-02 Method for mandating functions by Applet

Publications (1)

Publication Number Publication Date
CN101826004A true CN101826004A (en) 2010-09-08

Family

ID=42689936

Family Applications (1)

Application Number Title Priority Date Filing Date
CN200910046864A Pending CN101826004A (en) 2009-03-02 2009-03-02 Method for mandating functions by Applet

Country Status (1)

Country Link
CN (1) CN101826004A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107025109A (en) * 2015-12-26 2017-08-08 英特尔公司 The technology quoted using the native code of Binary analysis
CN108259418A (en) * 2016-12-28 2018-07-06 中移(苏州)软件技术有限公司 A kind of system and method for function trusteeship service
CN111475259A (en) * 2020-04-02 2020-07-31 北京百度网讯科技有限公司 Applet loading method and device and electronic equipment

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107025109A (en) * 2015-12-26 2017-08-08 英特尔公司 The technology quoted using the native code of Binary analysis
CN108259418A (en) * 2016-12-28 2018-07-06 中移(苏州)软件技术有限公司 A kind of system and method for function trusteeship service
CN111475259A (en) * 2020-04-02 2020-07-31 北京百度网讯科技有限公司 Applet loading method and device and electronic equipment

Similar Documents

Publication Publication Date Title
CN102981884B (en) Serializing device and sequencing method
US9304672B2 (en) Representation of an interactive document as a graph of entities
EP2296098A3 (en) System and method for merging remote and local data in a single user interface
CN101826004A (en) Method for mandating functions by Applet
CN104079926B (en) A kind of video performance method of testing of remote desktop software
Gabrel et al. Optimal and automatic transactional web service composition with dependency graph and 0-1 linear programming
WO2007085121A1 (en) Scheduling multithreaded programming instructions based on dependency graph
SE0004904D0 (en) Method of storing information
Taher et al. Adaptation of web service interactions using complex event processing patterns
CN101697136A (en) Method and device for controlling resource
Corradini et al. A technique for collaboration discovery
US10402707B2 (en) Interactive optical code creation
Fleischhack et al. A compositional Petri net semantics for SDL
CN109522348A (en) A kind of data processing system and method merging multiple intellectual analysis language
JP2007286694A (en) Progress management system and progress level calculation method
CN109800330A (en) A kind of data processing method and device
CN101866300B (en) Method for depositing function by thread
CN108156230A (en) Real-time data synchronization method, system and frame
CN104426761A (en) Message processing method and device
US20020196269A1 (en) Method and apparatus for real-time rendering of edited video stream
CN103778129B (en) A kind of blog data searching method and system
CN106709279B (en) Automate primer selection method and system
Nash Using Z to describe large systems
CN112035094B (en) Shuttle frame implementation method and device based on Vuetify frame
CN107844327A (en) A kind of detecting system and detection method for realizing context uniformity

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C12 Rejection of a patent application after its publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20100908