|
Custom Application Management
 |
The Application Manager, is a mechanism that provides application specific information through the Application intrinsic object (class CSPApplication).
CSP, besides the built-in Application Manager, supports external custom or third party Application Managers. Although the way an Application Manager is implemented is up to the developer, there are a few implementation rules.
The Application Manager is a DLL that must implement and export a few functions:
- CSPERROR _CSPAPPMNG_GetValue( const CSPString& strAppID [IN], const CSPString& strName [IN], CSPVariant& Value [OUT]);
This function is called by CSP to retrieve application information. The string strAppID contains the ID of the application that the requested .csp script belongs to, and the string strName contains the name of the information item to retrieve.
The function must search for the information item using the strAppID and strName as keys, and store the information in the Value object.
If the application information is found and successfully put in the Value object, the function must return CSP_OK. If not found, it must return CSP_APPLICATION_DATA_NOT_FOUND.
In case an unrecoverable error occurs during the execution, it must return CSP_ERROR_CANNOT_RETRIEVE_APPLICATION_DATA.
- CSPERROR _CSPAPPMNG_SetValue( const CSPString& strAppID [IN], const CSPString& strName[IN], const CSPVariant& Value [IN]);
This function is called by CSP to save application information. The string strAppID contains the ID of the application that the requested .csp script belongs to, and the string strName contains the name of the information item to save.
The function must save the application information in any manner preferred, using strAppID and strName as keys for later retrieval.
If the application information is successfully saved, the function must return CSP_OK. In case an unrecoverable error occurs during the execution, it must return CSP_ERROR_CANNOT_SAVE_APPLICATION_DATA.
- bool _CSPAPPMNG_Flush();
This function is periodically triggered by CSP Engine in order to perform maintenance tasks, cleanup or any other periodical process.
If successful, it must return true. If an unrecoverable error occurs, it must return false. The implementation of this function is optional.
- bool _CSPAPPMNG_Lock( const CSPString& strAppID );
Because the application information is shared among the scripts of a web application, there is a need for a method of exclusive use through locking.
This function increases the lock count of the application information bound to the application ID contained in strAppID, so that only the current thread can access the information.
It is important to notice that the Application Manager is responsible for handling any thread context related issues.
If successful, it must return true. If an unrecoverable error occurs, it must return false.
- bool _CSPAPPMNG_Unlock( const CSPString& strAppID );
This function decreases the lock count of the information bound to the application ID contained in strAppID. If successful, it must return true.
Even if the lock count is zero, it must return true. In case of an unrecoverable error, it must return false.
- bool _CSPAPPMNG_FullUnlock(const CSPString& strAppID);
This function ensures that the application information bound to the application ID contained in strAppID will be completely unlocked setting the lock count to zero.
If successful, it must return true. If an unrecoverable error occurs, it must return false.
- bool _CSPAPPMNG_OnInitApp(const CSPString& strAppID);
This function performs initialization tasks for the application whose ID is contained in strAppID. It is called once, when the related application is loaded by CSP.
If successful, it must return true. If an unrecoverable error occurs, it must return false. The implementation of this function is optional.
- bool _CSPAPPMNG_OnCleanupApp(const CSPString& strAppID);
This function performs clean-up tasks for the application whose ID is contained in strAppID. It is called once, when the related application is freed by CSP.
If successful, it must return true. If an unrecoverable error occurs, it must return false. The implementation of this function is optional.
- bool _CSPAPPMNG_OnLoad(const CSPString& strAppID);
This function performs initialization tasks for the entire Application Manager. It is called once, when CSP is loaded by the system.
If successful, it must return true. If an unrecoverable error occurs, it must return false. The implementation of this function is optional.
- bool _CSPAPPMNG_OnUnload(const CSPString& strAppID);
This function performs clean-up tasks for the entire Application Manager. It is called once, when CSP is unloaded by the system.
If successful, it must return true. If an unrecoverable error occurs, it must return false. The implementation of this function is optional.
When implementing an Application Manager, you must include the files CSPVariant.h, CSPString.h, and CSPDefs.h. Also, you must link it to CSPLib.lib or libCSPLib.a, depending on the compiler in use. These files are placed in the "include" and "lib" directories of CSP Engine.
See Control Console for more information about these directories.
It is important to notice that you must use the same compiler used by the installed version of CSP.
You must also compile with the option "/D _CSP_WINDOWS_", or you must define "#define _CSP_WINDOWS_" before you include any header file. Finally, the application manager DLL must export the functions above using symbols identical to the function names:
- _CSPAPPMNG_GetValue
- _CSPAPPMNG_SetValue
- _CSPAPPMNG_Flush
- _CSPAPPMNG_Lock
- _CSPAPPMNG_Unlock
- _CSPAPPMNG_FullUnlock
- _CSPAPPMNG_OnInitApp
- _CSPAPPMNG_OnCleanupApp
- _CSPAPPMNG_OnLoad
- _CSPAPPMNG_OnUnload
|
|
|
|