home *** CD-ROM | disk | FTP | other *** search
- #include "CDTrayServer.h"
- #include "TR_NetworkTypes.h"
- #include "TR_Buffer.h"
- #include "CDTrayControl.h"
-
- const UInt32 kRequestBufferSize = 1; // size of expected request
- const UInt32 kResponseDataSize = 1; // size of response
- const UInt32 kInitialPoolSize = 5; // initial number of simultanious requests
- const UInt32 kMinPoolFree = 1; // limit at which we will grow the pool
- const UInt32 kPoolGrowSize = 5; // size we will grow the pool by
- const UInt32 kMaxPoolSize = 15; // max size of the pool
-
-
- CDTrayServer::CDTrayServer(OSStatus& outErr)
- : fRespBufferPool(kResponseDataSize,kInitialPoolSize,kMinPoolFree,kPoolGrowSize,
- kMaxPoolSize)
- {
- fResponder = NULL;
- fActiveQ = false;
- // create a name for my server
- // this will use the "sharing setup" name with the NBP type of "Math Server"
-
- TR_NetworkName myName("\pCDTrayServer");
-
- // ask the factory to construct me a responder.
-
- outErr = TR_ResponderFactory::New(myName,kInitialPoolSize,kMinPoolFree,kPoolGrowSize,
- kMaxPoolSize,kRequestBufferSize,NULL,
- fResponder);
-
- // if things are good, attach myself to the responder as an event receiver
-
- if(outErr == noErr){
- fResponder->AttachEventReceiver(this);
- }
- }
-
-
- CDTrayServer::~CDTrayServer()
- {
- // we are closing down, so lets remove ourselves from the responder
- // and delete it.
-
- if(fResponder != NULL){
- fResponder->RemoveEventReceiver(this);
- delete fResponder;
- }
- }
-
-
-
- void CDTrayServer::Idle()
- {
- // give the responder idle time
-
- if(fResponder != NULL){
- fResponder->Idle();
- }
-
- // give any objectpools idle time
- // (this is being use by the TR_BufferPool object that is managing my response buffers)
-
- PO_ObjectPool::Idle();
-
-
-
- // NOTE if we were not processing requests when they come in,
- // we could be using the TR_RequestIterator object
- // to process them here....
-
- if(fActiveQ){
- StartTrayCycle();
- }else{
- StopTrayCycle();
- }
-
- IdleTray();
- }
-
-
-
-
-
- void CDTrayServer::NotifyNewRequest(TR_Responder* inResponder,TR_RequestCookie inRequest)
- {
- // this function gets called at interrupt when a new request comes in.
-
- // first off, we will ask to handle the request by trying to "commit" to it
- // if we get back a non NULL pointer, then we OWN the request.
- // if we get back a NULL pointer, then someone else got it already...
-
-
- TR_IncommingRequest* thisRequest = inResponder->CommitRequest(inRequest);
-
- if(thisRequest != NULL){
-
- // ok, we got the request, now lets fetch the associated request buffer
- // we see what kind of request we are going to handle.
-
- PO_Ref<TR_Buffer> reqBuffer = thisRequest->GetRequestBuffer();
-
- // I assert that the size of the request should be
- // the size of my param structure.
-
-
-
- // ok, now cast the buffer to my param structure and examine the contents.
- // we support two operations: Adding, multiplying and fetching the "status"
- // which is really just the current "pool size" of the responder.
-
- // for the sake of illustration, we will handle
- // adding and status right here and now, but we
- // will defer multiplying to a "safe" time using the
- // TR_DeferredAction class
-
- bool* param = (bool*) reqBuffer->GetBuffer();
-
- fActiveQ = *param;
-
- PO_Ref<TR_Buffer> respBuffer;
-
- if(fRespBufferPool.Allocate(respBuffer,1)){
-
- // stuff in the result in a way that would make any "C" programmer
- // proud!
-
- *((char*) respBuffer->GetBuffer()) = 0;
-
-
- thisRequest->SendResponse(respBuffer,NULL,true);
- }
- }
- }
-
-
- void CDTrayServer::NotifyResponseComplete(TR_Responder* inResponder,
- TR_IncommingRequest* inRequest,
- void* inUserData)
- {
- // we don't care about this stuff
-
- (void) inResponder;
- (void) inRequest;
- (void) inUserData;
- }
-
-
-
-
-