Apple Network Setup Network Card User Manual


 
CHAPTER 2
Using Network Setup
28 Opening and Closing the Network Setup Database
Closing the Database After Reading 2
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-3 Closing 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 2
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.