/***********************************************************************
 * 
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; version 2.1
 *  of the License.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, Novell, Inc.
 * 
 *  To contact Novell about this file by physical or electronic mail, 
 *  you may find current contact information at www.novell.com.
 * 
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 *
 ***********************************************************************/


#ifndef _CLIENTREQ_
#define _CLIENTREQ_

//===[ Include files ]=====================================================

//===[ External data ]=====================================================

//===[ External prototypes ]===============================================

//===[ Manifest constants ]================================================

//===[ Type definitions ]==================================================

//===[ Function prototypes ]===============================================

//===[ Global variables ]==================================================

//===[ Type definitions ]==================================================

//
// Client Request Class
//
class ClientReq
{
   // Req Id
   uint32_t                m_reqId;

   // Server Data
   char                    *m_pServerData;
   uint32_t                m_serverDataLen;

   // Flag indicating the state of the submitting
   // thread.
   bool                    m_submitThreadActive;

   // Flag indicating that the Request has completed.
   bool                    m_completed;

   // Flag indicating that a problem was encountered
   // while processing the Request.
   bool                    m_internalProblem;

   // Synchronization variables
   pthread_mutex_t         m_mutex;
   pthread_cond_t          m_condition;

public:

   // Completion Statuses
   enum CompletionStatus
   {
      SuccessCompletionStatus = 1,
      ErrorCompletionStatus
   };

   //
   // Constructor
   //
   // Parameters:
   //    reqId (input) -
   //       Id of the Request.
   //
   //    clientHandler (input) -
   //       Pointer to Client Handler routine.
   //
   // Abstract: Constructs ClientReq object.
   //
   // Returns: Nothing.
   //
   ClientReq(uint32_t reqId);

   //
   // Destructor
   ~ClientReq(void);

   //
   // Process Server Data routine
   //
   // Parameters:
   //    pServerData (input) -
   //       Pointer to buffer containing the server data.
   //       Buffer is released by call to the routine.
   //
   //    serverDataLength (input) -
   //       Length of the server data.
   //
   // Abstract: Processes server data.
   //
   // Returns: Nothing.
   //
   void processServerData(char *pServerData,
                          uint32_t serverDataLength);

   //
   // Process Error routine
   //
   // Parameters: None.
   //
   // Abstract: Processes channel and server error
   //           indication.
   //
   // Returns: Nothing.
   //
   void processError(void);

   //
   // Wait For Completion routine
   //
   // Parameters:
   //    ppResponseData (input/output) -
   //       Pointer to variable that will receive pointer to
   //       buffer containing the data sent by the server.
   //
   //    pResponseDataLength (input/output) -
   //       Pointer to variable that will receive the length
   //       of the data sent by the server.
   //
   //
   // Abstract: Waits for the Request completion.
   //
   // Returns: 0 == Request completed gracefully
   //          -1 == Request did not complete gracefully
   //
   int waitForCompletion(char **ppResponseData,
                         uint32_t *pResponseDataLength);

   //
   // Completion status
   //
   // Parameters: None.
   //
   // Abstract: Obtains the request completion status.
   //
   // Returns: Request completion status.
   //          status in order to find out.
   //
   ClientReq::CompletionStatus completionStatus(void);
};


//===[ Function prototypes ]===============================================


#endif // _CLIENTREQ_

//=========================================================================
//=========================================================================