|
| 以 PDF 格式下载本书
KcsIO Derivative
4
- This chapter discusses the following topics to help you create a KcsIO class derivative that is dynamically loadable at runtime:
-
- External entry points with an example
- Member function override rules
- Pointer to the KcsSolarisFile class source code to use as an example of a KcsIO derivative
External Entry Points
- The KCMS framework uses external entry points to load your derivative as an executable. The mandatory and optional entry points are described.
Mandatory
- When you derive from a KcsIO class, the mandatory external entry points are:
-
extern long KcsDLOpenIOCount;
KcsIO *KcsCreateIO(KcsStatus *aStat,
const KcsProfileDesc *aDesc);
|
- The KcsCreateIO() method creates an instance of a KcsIO derivative. The instance is determined by aDesc->type, which contains the derivative portion of the class identifier (see "OWconfig File Structure" on page 24).
Optional
- When you derive from a KcsIO class, the optional external entry points are:
-
KcsStatusId KcsInitIO();
KcsStatusId KcsCleanupIO();
|
Example
- The following example shows you how to use the entry points when creating a KcsIO derivative.
-
Code Example 4-1 KcsIO Class Entry Points Example
-
/* External loadable interface */
extern "C"
extern long KcsDLOpenIOCount;
KcsStatus KcsInitIO();
KcsIO *KcsCreateIO(KcsStatus *aStatus,
const KcsProfileDesc *aDesc);
KcsStatus KcsCleanupIO();
}
//Loadable stuff
//external DL open count to support runtime derivation
extern long KcsDLOpenIOCount = 0;
/* Runtime derivable routine */
KcsIO *
KcsCreateIO(KcsStatus *aStat, const KcsProfileDesc *Desc)
{
//Create the new derivative
return(new KcsSolarisFile(aStat, aDesc->desc.solarisFile.fileName,
aDesc->desc.solarisFile.hostName,
aDesc->desc.solarisFile.oflag, aDesc->desc.solarisFile.mode);
}
KcsStatus
KcsInitIO(long libMajor, long libMinor, long *myMajor, long *myMinor)
{
// Set up the return values
*myMajor = KCS_MAJOR_VERSION;
*myMinor = KCS_MINOR_VERSION;
if (libMinor < KCS_MINOR_VERSION)
|
-
Code Example 4-1 KcsIO Class Entry Points Example (Continued)
-
//Check the major version
if (libMajor != KCS_MAJOR_VERSION)
return (KCS_CMM_MAJOR_VERSION_MISMATCH);
//Currently, if minor version of library is less than the KCMS
// minor version, return an error.
if (libMinor != KCS_MINOR_VERSION)
return (KCS_CMM_MINOR_VERSION_MISMATCH);
//Library guarantees if your minor version number is greater than
//KCMS minor version number, it will handle it. No more init.
return(KCS_SUCCESS);
}
KcsStatus KcsCleanupIO()
{
/* Clean up is performed in the destructor */
return;
}
if (libMinor < KCS_MINOR_VERSION)
|
Member Function Override Rules
- The following table tells you which KcsIO member functions you must override, can override, and should not override when deriving from this class. The member functions indicated with an "X" in the Must column are required to successfully derive from this base class. All of these member functions are defined in the kcsio.h header file and the KCMS CMM Reference Manual.
-
Table 4-1 KcsIO
| Member Function....Must | Override Rules
Can
| Do Not |
| absRead() |
|
| X |
| absWrite() |
|
| X |
| copyData() |
|
| X |
| createIO() |
|
| X |
| getEOF() | X |
|
|
-
Table 4-1 KcsIO(Continued)
| Member Function....Must | Override Rules
Can
| Do Not |
| getOffset() |
|
| X |
| getType() | X |
|
|
| isEqual() | X |
|
|
| KcsIO() | X |
|
|
| setCursorPos() | X |
|
|
| setEOF() | X |
|
|
| ~KcsIO() |
| X |
|
| relRead() | X |
|
|
| relWrite() | X |
|
|
| replaceData() |
|
| X |
| setOffset() |
| X |
|
The KcsSolarisFile Derivative as an Example
- The KcsSolarisFile class is a derivative of the KcsIO class. Any KcsSolarisFile files (or any of the other KcsIO derivatives) are good sources of example code for creating a KcsIO derivative. The on-line files /usr/opt/SUNWddk/kcms/src/kcssolfi.cc and kcssolfi.h are actual SunSoft source code that supports enhanced file access on Solaris. This source code is directly tied into the kcstypes.h header file. The kcssolfitest.h header file explains how to include this derivative without changing the KCMS header file.
|
|