Apple Network Setup manual Closing the Database After Reading, Closing the Database After Writing

Models: Network Setup

1 184
Download 184 pages 5.56 Kb
Page 28
Image 28
Closing the Database After Reading

C H A P T E R 2

Using Network Setup

Closing the Database After Reading

The MyCloseDatabaseAfterReading routine shown in Listing 2-3 shows how to close the database after you are done reading from it. The routine simply calls OTCfgCloseArea to close the read area and then calls OTCfgCloseDatabase to close the database itself. This code discards error results from both of these routines because if the database fails to close there isn’t anything your application can do to force it to close, but it does log any errors with the standard C assert macro so that you can detect this sort of error during testing.

Listing 2-3Closing the database after reading

static void MyCloseDatabaseAfterReading(CfgDatabaseRef dbRef, CfgAreaID readArea)

{

OSStatus junk;

assert(dbRef

!=

nil);

assert(readArea !=

kInvalidCfgAreaID);

junk = OTCfgCloseArea(dbRef, readArea); assert(junk == noErr);

junk = OTCfgCloseDatabase(&dbRef); assert(junk == noErr);

}

Closing the Database After Writing

The MyCloseDatabaseAfterWriting routine shown in Listing 2-4 shows how to close the database after you have finished making changes. The first three routine parameters (the database reference, the read area identifier, and the write area identifier) were obtained when the database was opened the database for writing. The fourth parameter, commit, indicates whether the changes are to be committed to the database or discarded.

If commit is true, the routine calls OTCfgCommitAreaModifications, which overwrites the current settings in the read area with the new settings in the write area and notifies the network protocol stacks that their preferences have changed so that they can reconfigure themselves.

28Opening and Closing the Network Setup Database

Page 28
Image 28
Apple Network Setup manual Closing the Database After Reading, Closing the Database After Writing