home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
VISBUILD
/
RAPSHEET
/
CPPOV23
/
ILSRMGR.CPP
< prev
next >
Wrap
Text File
|
1995-05-22
|
11KB
|
306 lines
//****************************************************************************
// ILastSeenClientMgr Class - C++ Source File (ilsrmgr.cpp) *
// *
// COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
// *
// DISCLAIMER OF WARRANTIES: *
// The following [enclosed] code is sample code created by IBM *
// Corporation. This sample code is not part of any standard IBM product *
// and is provided to you solely for the purpose of assisting you in the *
// development of your applications. The code is provided "AS IS", *
// without warranty of any kind. IBM shall not be liable for any damages *
// arising out of your use of the sample code, even if they have been *
// advised of the possibility of such damages. *
//****************************************************************************
//NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
//
#include "ilsrmgr.hpp" //ILastSeenClientMgr header
#ifndef _INOTIFEV_
#include "inotifev.hpp"
#endif
#ifndef _ITRACE_
#include <itrace.hpp>
#endif
#include "irsltrec.hpp" //IResultRecord header
#include "ilsrec.hpp" //ILastSeenRecord header
#include "ilstseen.hpp" //ILastSeen header
#include <iadd.hpp> //IAddress header
#include "querydb.hpp" //temp (for scaffold testing)
/*******************************************************************
* Events
*******************************************************************/
INotificationId ILastSeenClientMgr :: parsedResultId = "ILastSeenClientMgr::parsedResult";
INotificationId ILastSeenClientMgr :: requestBufferId = "ILastSeenClientMgr::requestBuffer";
INotificationId ILastSeenClientMgr :: resultBufferId = "ILastSeenClientMgr::resultBuffer";
INotificationId ILastSeenClientMgr :: resultListId = "ILastSeenClientMgr::resultList";
INotificationId ILastSeenClientMgr :: resultListWrapperId = "ILastSeenClientMgr::resultListWrapper";
INotificationId ILastSeenClientMgr :: resultObjectId = "ILastSeenClientMgr::resultObject";
INotificationId ILastSeenClientMgr :: resultWrapperId = "ILastSeenClientMgr::resultWrapper";
INotificationId ILastSeenClientMgr :: sameRequestId = "ILastSeenClientMgr::sameRequest";
INotificationId ILastSeenClientMgr :: noObjectsFoundId = "ILastSeenClientMgr::noObjectsFound";
INotificationId ILastSeenClientMgr :: oneObjectFoundId = "ILastSeenClientMgr::oneObjectFound";
INotificationId ILastSeenClientMgr :: manyObjectsFoundId = "ILastSeenClientMgr::manyObjectsFound";
/*******************************************************************
* Constructors
*******************************************************************/
ILastSeenClientMgr :: ILastSeenClientMgr() :
dRequestBuffer(""),
dResultBuffer(""),
dResultWrapper(0),
dResultListWrapper(new IVSequence<ILastSeen *>)
{
enableNotification();
dResultListWrapper->enableNotification();
}
/*******************************************************************
* Destructor
*******************************************************************/
ILastSeenClientMgr :: ~ILastSeenClientMgr()
{
if (dResultWrapper)
delete dResultWrapper;
if (dResultListWrapper)
delete dResultListWrapper;
}
/*******************************************************************
* Attribute Access Member Functions
*******************************************************************/
/*------------------------------------------------------------------
* requestBuffer
*-----------------------------------------------------------------*/
IString ILastSeenClientMgr :: requestBuffer () const
{
return dRequestBuffer;
}
ILastSeenClientMgr & ILastSeenClientMgr ::
setRequestBuffer (const IString & iRequestBuffer)
{
if (dRequestBuffer != iRequestBuffer)
{
dRequestBuffer = iRequestBuffer;
notifyObservers(INotificationEvent(requestBufferId, *this, true,
IEventData((char *)iRequestBuffer)));
}
else
notifyObservers(INotificationEvent(sameRequestId, *this, false));
return *this;
}
/*------------------------------------------------------------------
* resultBuffer
*-----------------------------------------------------------------*/
IString ILastSeenClientMgr :: resultBuffer () const
{
return dResultBuffer;
}
ILastSeenClientMgr & ILastSeenClientMgr ::
setResultBuffer (const IString & iResultBuffer)
{
if (dResultBuffer != iResultBuffer)
{
dResultBuffer = iResultBuffer;
notifyObservers(INotificationEvent(resultBufferId, *this, true,
IEventData((char *)iResultBuffer)));
} /* endif */
return *this;
}
/*------------------------------------------------------------------
* resultList (read-only) and resultListWrapper
*-----------------------------------------------------------------*/
IVSequence <ILastSeen *> ILastSeenClientMgr ::
resultList () const
{
return *dResultListWrapper;
}
IVSequence <ILastSeen *> * ILastSeenClientMgr ::
resultListWrapper () const
{
return dResultListWrapper;
}
/*------------------------------------------------------------------
* resultObject and resultWrapper (read-only)
*-----------------------------------------------------------------*/
ILastSeen * ILastSeenClientMgr :: resultWrapper () const
{
return dResultWrapper;
}
ILastSeen ILastSeenClientMgr :: resultObject () const
{
return *dResultWrapper;
}
/*******************************************************************
* Actions
*******************************************************************/
/*------------------------------------------------------------------
* allbyBookNumber
*-----------------------------------------------------------------*/
IString ILastSeenClientMgr :: allByBookNumber (unsigned long aBookNumber)
{
IResultRecord rsltRec;
IString suspectKey = IString(aBookNumber);
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("suspectKey: " + suspectKey + ".");
if (dRequestBuffer != suspectKey)
{
setRequestBuffer(suspectKey);
ITRACE_DEVELOP("Calling the DB server.");
rsltRec = getAllLastSeen(aBookNumber);
ITRACE_DEVELOP("Number last seen locations found: " + IString(rsltRec.numResults()));
}
else
setRequestBuffer(suspectKey);
return rsltRec.asString();
}
/*------------------------------------------------------------------
* processResult()
* The user controls when dResultBuffer should be processed.
*-----------------------------------------------------------------*/
ILastSeenClientMgr & ILastSeenClientMgr :: processResult ()
{
ILastSeen *lastSeen;
ILastSeenRecord lastSeenRec;
IAddress address;
unsigned short recOffset, i;
IString buffer;
IFUNCTRACE_DEVELOP();
if (!dResultBuffer.isWhiteSpace())
{
IResultRecord resultRec(dResultBuffer);
//clear the result list if it's not empty (i.e., if it was set in a previous invocation)
if (dResultListWrapper->numberOfElements())
dResultListWrapper->removeAll();
recOffset = 1;
for (i=0 ; i < resultRec.numResults(); i++)
{
lastSeen = new ILastSeen;
buffer = resultRec.resultData().subString(
recOffset,lastSeenRec.size());
lastSeenRec = buffer;
lastSeen->setLocation(lastSeenRec.location());
lastSeen->setWitness(lastSeenRec.witness());
lastSeen->setDateLastSeen(lastSeenRec.lastSeenDate());
lastSeen->setComment(lastSeenRec.comment());
address.setStreet(lastSeenRec.street());
address.setCity(lastSeenRec.city());
address.setState(lastSeenRec.state());
address.setZip("");
lastSeen->setAddress(new IAddress ( address ));
addResult(lastSeen); //adds lastSeen to
//the result list
recOffset += lastSeenRec.size(); //get the next lastSeenRec
}
notifyObservers(INotificationEvent(parsedResultId, *this, false));
if (resultRec.numResults() == 1)
notifyObservers(INotificationEvent(oneObjectFoundId, *this, false));
else if (resultRec.numResults() == 0)
{
notifyObservers(INotificationEvent(noObjectsFoundId, *this, false));
throw IException("No information exists for the specified suspect.");
}
else
notifyObservers(INotificationEvent(manyObjectsFoundId, *this, false));
}
return *this;
}
/*******************************************************************
* Class Member Functions
*******************************************************************/
/*------------------------------------------------------------------
* addResult()
*-----------------------------------------------------------------*/
ILastSeenClientMgr & ILastSeenClientMgr ::
addResult (ILastSeen * iLastSeenWrapper)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("addResult(*) of ilsrmgr.");
if (dResultListWrapper->isEmpty())
{
setResultWrapper(iLastSeenWrapper);
}
dResultListWrapper->add(iLastSeenWrapper);
return *this;
}
/*------------------------------------------------------------------
* addResult()
*-----------------------------------------------------------------*/
ILastSeenClientMgr & ILastSeenClientMgr ::
addResult (ILastSeen & iLastSeen)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("addResult(&) of ilsrmgr.");
if (dResultListWrapper->isEmpty())
{
setResultWrapper(&iLastSeen);
}
dResultListWrapper->add(&iLastSeen);
return *this;
}
/*------------------------------------------------------------------
* setResultWrapper()
*-----------------------------------------------------------------*/
ILastSeenClientMgr & ILastSeenClientMgr ::
setResultWrapper (ILastSeen * iResultWrapper)
{
if (dResultWrapper != iResultWrapper)
{
if (dResultWrapper)
delete dResultWrapper;
dResultWrapper = iResultWrapper;
notifyObservers(INotificationEvent(resultObjectId, *this, false));
notifyObservers(INotificationEvent(resultWrapperId, *this, false));
}
return *this;
}
/*------------------------------------------------------------------
* setResultWrapper()
*-----------------------------------------------------------------*/
ILastSeenClientMgr & ILastSeenClientMgr ::
setResultWrapper (const ILastSeen & iResult)
{
/*****************************************************************
* Have to make a copy of the ILastSeen object passed in since it's
* identified as being a const. That is, the compiler won't
* allow dResultWrapper = &iResultWrapper, since it would allow
* us, via dResultWrapper, to update the ILastSeen object.
*****************************************************************/
return setResultWrapper(new ILastSeen(iResult));
}