home *** CD-ROM | disk | FTP | other *** search
- // BDE - (C) Copyright 1995 by Borland International
-
- // session.c
- #include "snipit.h"
-
- //=====================================================================
- // Function:
- // SessionIO();
- //
- // Description:
- // This example will demonstrate how to start more than one
- // session. The example also shows how to switch between
- // sessions.
- //=====================================================================
- void
- SessionIO (void)
- {
- DBIResult rslt; // Value returned from IDAPI functions
- phDBISes phSession = NULL; // Handle to the session
- pSESInfo pSesInfo = NULL; // Session descriptor
- UINT16 i; // Loop variable
- const UINT uNumOfSessions = 4 ; // The number of sessions to open
-
- Screen("*** Session I/O Example ***\r\n");
-
- BREAK_IN_DEBUGGER();
-
- Screen(" Initializing IDAPI...\r\n");
-
- rslt = DbiInit(NULL);
- if (ChkRslt(rslt, "Init") != DBIERR_NONE)
- {
- Screen("\r\n*** End of Example ***");
- return;
- }
-
- // Turn on trace information if the debug layer is anabled (DLLSWAP.EXE).
- DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
-
- // Specify where temporary files are placed.
- rslt = DbiSetPrivateDir(szPrivDirectory);
- ChkRslt(rslt, "SetPrivateDir");
-
- // Allocate memory for uNumOfSessions sessions. These
- // will be pointers to sessions once we start them.
- phSession = (phDBISes) malloc(uNumOfSessions * sizeof(hDBISes));
- // Allocate memory for the session information pointers.
- pSesInfo = (pSESInfo) malloc(uNumOfSessions * sizeof(SESInfo));
- if ((phSession == NULL) || (pSesInfo == NULL))
- {
- if (phSession) free(phSession);
- if (pSesInfo) free(pSesInfo);
- Screen(" Error - Out of memory");
- DbiDebugLayerOptions(0, NULL);
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
- Screen("\r\n*** End of Example ***");
- return;
- }
-
- // Acquire the initial session handle. A session is started for you
- // when the engine is initialized.
- Screen(" Getting session #1 (opened automatically by DbiInit)...");
-
- rslt = DbiGetCurrSession( &(phSession[0]) );
- ChkRslt(rslt, "GetCurrSession");
-
- // Start new sessions and display the number of open sessions on the
- // screen. Having already opened the first one, start the second
- // session through the uNumOfSessions - 1 session.
- for (i=0; i<(uNumOfSessions - 1); i++)
- {
- Screen("\r\n Opening session #%d...",i+2);
- rslt = DbiStartSession("", &(phSession[i+1]), NULL);
- ChkRslt(rslt, "StartSession");
- }
-
- // Now iterate through each of the sessions and get the current
- // settings. The settings include the session number, the number of
- // open databases and the number of open cursors, among other things.
- for (i=0; i<uNumOfSessions; i++)
- {
- Screen("\r\n Setting session #%d as the current session...",i+1);
- rslt = DbiSetCurrSession(phSession[i]);
- ChkRslt(rslt, "SetCurrSession");
-
- Screen(" Getting session information...");
- rslt = DbiGetSesInfo( &(pSesInfo[i]) );
- ChkRslt(rslt, "GetSesInfo");
-
- Screen(" Open databases: %d, Open cursors: %d",
- pSesInfo[i].iDatabases, pSesInfo[i].iCursors);
- }
-
- // Close the sessions.
- Screen("\r\n We cannot yet close session #1 as it is the default"
- " session");
- Screen(" We will therefore close all other sessions and then close"
- " session #1");
- for (i=0; i<(uNumOfSessions-1); i++)
- {
- // We cannot close session #1 so we will close session #2
- // and on. We cannot close session #1 because it is the
- // default session (created with DbiInit.)
- Screen("\r\n Closing session #%d...",i+2);
-
- rslt = DbiCloseSession(phSession[i+1]);
- ChkRslt(rslt, "CloseSession");
- }
-
- // Release the memory used to hold the session handles.
- free(phSession);
-
- // Release the memory used to store information about the session.
- free(pSesInfo);
-
- // Turn off trace information.
- DbiDebugLayerOptions(0, NULL);
-
- Screen("\r\n Closing session #1 (done during DbiExit)");
- Screen("\r\n Clean up IDAPI...");
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
-
- Screen("\r\n*** End of Example ***");
- }
-