LInet::CommandCallBack

#include " ltwrappr.h "

virtual L_INT LInet::CommandCallBack(plConnection, uCommand, uCommandID, nError, uParams, pParams, uExtra, pExtra)

LInet L_FAR * plConnection;

/* instance of a remote computer */

CMDTYPE uCommand;

/* command type */

L_UINT uCommandID;

/* command id */

L_INT nError;

/* status of the received data */

L_UINT uParams;

/* number of parameters */

pPARAMETER pParams;

/* pointer to an array of parameters */

L_UINT uExtra;

/* length */

L_CHAR L_FAR * pExtra;

/* pointer to extra data */

Notifies a computer that a command has been received. This function is only available in the Internet toolkit.

Parameter

Description

plConnection

Instance of the remote computer from which the command was sent.

uCommand

Command received from the remote computer. For a list of possible values, refer to CMDTYPE.

uCommandID

Command Id. Each command sent by a member of a connection should have a unique ID. Since a member of a connection may send several messages, this ID allows that member to identify when a specific request has been completed.

nError

Determines whether the command was received properly. If not all the parameters were received properly, then nError will be set to an error code (usually ERROR_TRANSFER_ABORTED).

uParams

The number of parameters for this command.

pParams

Pointer to an array of PARAMETER structures that contain the parameters for the command.

uExtra

Length of any extra data sent with the command.

pExtra

Pointer to the extra data sent with the command.

Returns

SUCCESS

This function was successful.

< 1

An occurred. Refer to Return Codes.

Comments

A call to this overridable function is generated when a computer receives a command request from a remote computer.

To process commands, a class must be derived from LInet and this member function must be overridden.

When a command request is received, this function should respond by calling the corresponding response function. For example, if a SendLoadCmd request is received from a remote computer, this function should respond by calling LInet::SendLoadRsp.

Required DLLs and Libraries

LTNET

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

LInet::ResponseCallBack, LInet::SendCmd, LInet::SendLoadCmd, LInet::SendCreateWinCmd, LInet::SendAttachBitmapCmd, LInet::SendSaveCmd, LInet::SendSizeWinCmd, LInet::SendShowWinCmd, LInet::SendCloseWinCmd, LInet::SendFreeBitmapCmd, LInet::SendSetRectCmd

Topics:

Sending Commands and Responses

 

A Client Server Diagram: Sending Commands and Responses

Example

/*Below is a sample CommandCallBack function that can be used to process various commands sent to a server*/
//The CommandCallBack() is processed on the server
//To process the commands sent to the computer, you must:
//1. Derive a class from LInet
//2. Override the CommandCallBack member function
//
//Assume that 
//1. m_Inet is an object of the class CMyNet (derived from LInet).
//2. the network as been started (LInet::StartUp()) 
//3. a connection has been established with a remote client
//4. UpdateStatusbar() displays a message in the status bar
//5. m_BitmapList maintains a list of LBitmapWindow objects

L_INT CMyNet::CommandCallBack(LInet L_FAR * plConnection,
                              CMDTYPE     uCommand,
                              L_UINT      uCommandID,
                              L_INT       nError,
                              L_UINT      uParams, 
                              pPARAMETER  pParams, 
                              L_UINT      uExtra,
                              L_CHAR L_FAR*pExtra)
{
   L_INT nStatus = ERROR_FEATURE_NOT_SUPPORTED;
   L_UINT          uBitmapID = (L_UINT)-1;
   
   CString strMsg;
   
   strMsg.Format(TEXT("%s, id=%d, nError=%d, uParams=%d%s received"), 
      GetCommandString(uCommand), 
      uCommandID, 
      nError, 
      uParams, 
      uExtra ? TEXT(", uExtra") : TEXT(""));
   UpdateStatusbar(strMsg, 0);
   
   CMainFrame *pMain;
   pMain = GETMAINFRAME;
   
   if(nError != SUCCESS)
      nStatus = ERROR_TRANSFER_ABORTED;
   else
      switch(uCommand)
      {
         case CMD_LOAD:
         {
            L_INT nIndex;

            nIndex = m_BitmapList.AddBitmap (
               pParams[0].pValue, //file name
               pParams[1].iValue, //nBitsPerPixel
               pParams[2].iValue  //nOrder
               );
            
            if (nIndex >=0)
            {
               nStatus = SUCCESS;
               pMain->m_uBitmapID = uBitmapID = nIndex;
            }

            return pMain->m_Inet.SendLoadRsp (plConnection, uCommandID, uBitmapID, 0, NULL, nStatus);
         }
         break;
         
         case CMD_CREATE_WIN:
         {
            pMain->m_bCreateBitmapWindow = FALSE; //Do not allocate LBitmapWindow
            pMain->m_pInetRemoteServer = plConnection;
            theApp.OnFileNew ();
            pMain->m_bCreateBitmapWindow = TRUE;
            pMain->m_pInetRemoteServer = NULL;
            nStatus = SUCCESS;
            
            // Get the active MDI child window.CMDIChildWnd 
            CMDIChildWnd *pChild = (CMDIChildWnd *) pMain->GetActiveFrame();
            CView *pView = pChild->GetActiveView();
            
            // Get the active view attached to the active MDI child window.
            pChild->SetWindowPos(NULL, 0, 0, pParams[5].iValue,pParams[6].iValue, SWP_NOOWNERZORDER + SWP_NOMOVE );
            pMain->m_uWindowID = (L_UINT)pView->m_hWnd;
            
            return pMain->m_Inet.SendCreateWinRsp (
               plConnection, 
               uCommandID, 
               (L_UINT)pView->m_hWnd, 
               0, 
               NULL, 
               SUCCESS);
         }
         break;
         
         case CMD_ATTACH_BITMAP:
         {
            L_UINT32 uBitmapID = pParams[0].uiValue;
            HWND uWindowID = (HWND)pParams[1].uiValue;
            
            //pParams[0] uBitmapID
            //pParams[1] uWindowID
            
            //Need to attach bitmap to BitmapWindow
            if (IsWndValid((HWND)uWindowID))
            {
               LBitmapWindow *pBitmapWindow;
               pBitmapWindow = m_BitmapList[uBitmapID];
               if (pBitmapWindow != NULL)
               {
                  pBitmapWindow-> SetWndHandle(uWindowID);
                  CNetDoc *pNetDoc = (CNetDoc*)GetDocFromHWnd((HWND)uWindowID);
                  if (pNetDoc != NULL)
                  {
                     pNetDoc->m_pBitmapWindow = pBitmapWindow;
                     pNetDoc->m_bBitmapWindowInList = TRUE;
                  }
               }
            }
            return pMain->m_Inet.SendAttachBitmapRsp (plConnection, uCommandID, 0, NULL, nStatus);
         }
         break;
         
         case CMD_FLIP:
         {
            uBitmapID = pParams->uiValue;
            
            //Make sure bitmap ID is valid
            LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID];
            if (pBitmapWindow != NULL)
            {
               nStatus = pBitmapWindow->Flip();
            }
         }
         break;
         
         case CMD_SAVE:
         {
            uBitmapID = pParams[1].uiValue;
            //Make sure bitmap ID is valid
            LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID];
            
            //pParams[0] file name
            //pParams[1] bitmap id
            //pParams[2] nFormat
            //pParams[3] nBitsPerPixel
            //pparams[4] nQFactor
            //pParams[5] uFlags
            
            if (pBitmapWindow != NULL)
            {   
               L_INT nRet;
               nRet = pBitmapWindow->Save(
                  pParams[0].pValue,
                  pParams[2].iValue,
                  pParams[3].iValue,
                  pParams[4].iValue,
                  pParams[5].iValue
                  );
               if (nRet != SUCCESS)
                  nStatus = FAILURE;
            }
         }
         return pMain->m_Inet.SendSaveRsp (plConnection, uCommandID,0, NULL, nStatus);
         break;
         
         case CMD_GET:
         {
            L_UINT   uBitmapID = pParams->uiValue;
            
            //is it a valid bitmap ID?
            LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID];
            if (pBitmapWindow != NULL)
            {
               //nStatus = m_Inet.SendBitmap (pBitmapWindow);
               nStatus = pMain->m_Inet.SendBitmap (plConnection, pBitmapWindow->GetHandle(), FILE_CMP, 24, QS, NULL);
            }         
         }
         break;
         
         case CMD_SIZE_WIN:
         {
            L_INT  nStatus = SUCCESS;
            L_INT  nRet;
            HWND   uWindowID = (HWND)pParams[0].uiValue;
            L_UINT uLeft   = pParams[1].uiValue;
            L_UINT uTop    = pParams[2].uiValue;
            L_UINT uWidth  = pParams[3].uiValue;
            L_UINT uHeight = pParams[4].uiValue;
            
            if (IsWndValid((HWND)uWindowID))
            {
               nRet = ::SetWindowPos(
                  ::GetParent((HWND)uWindowID), 
                  NULL, 
                  uLeft, 
                  uTop, 
                  uWidth, 
                  uHeight, 
                  SWP_NOOWNERZORDER 
                  );
               if (nRet == 0)
                  nStatus = FAILURE;
            }
            else
            {
               nStatus = ERROR_INV_PARAMETER;
            }
            return pMain->m_Inet.SendSizeWinRsp (plConnection, uCommandID, 0, NULL, nStatus);
         }
         break;
         
         case CMD_SHOW_WIN:
         {
            L_INT  nStatus = SUCCESS;
            L_INT  nRet;
            HWND   uWindowID = (HWND)pParams[0].uiValue;
            L_INT  nCmdShow  = pParams[1].iValue;
            
            if (IsWndValid((HWND)uWindowID))
            {
               nRet = ::ShowWindow(
                  ::GetParent((HWND)uWindowID), 
                  nCmdShow
                  );
               if (nRet == 0)
                  nStatus = FAILURE;
            }
            else
            {
               nStatus = ERROR_INV_PARAMETER;
            }
            return pMain->m_Inet.SendShowWinRsp (plConnection, uCommandID, 0, NULL, nStatus);
         }
         break;
         
         case CMD_CLOSE_WIN:
         {
            L_INT nStatus = SUCCESS;
            HWND  uWindowID = (HWND)pParams[0].uiValue;
            
            if (!CloseDocument((HWND)uWindowID))
            {
               nStatus = ERROR_INV_PARAMETER;
            }
            return pMain->m_Inet.SendCloseWinRsp (plConnection, uCommandID, 0, NULL, nStatus);
         } 
         break;
         
         case CMD_FREE_BITMAP:
         {
            L_INT nStatus    = SUCCESS;
            L_UINT uBitmapID = pParams[0].uiValue;
            
            nStatus = m_BitmapList.DeleteBitmap (uBitmapID);
            pMain->UpdateWindow();
            return pMain->m_Inet.SendFreeBitmapRsp (plConnection, uCommandID, 0, NULL, nStatus);
         } 
         break;
         
         case CMD_SET_RECT:
         {
            L_INT nStatus = FAILURE;
            uBitmapID = pParams->uiValue;
            
            CNetDoc *pNetDoc = (CNetDoc*)GetDocFromHWnd(HWND(pParams[0].uiValue));
            
            if (pNetDoc != NULL)
            {
               RECT rcRect;
               rcRect.left   = pParams[2].iValue;
               rcRect.top    = pParams[3].iValue;
               rcRect.right  = rcRect.left + pParams[4].iValue;
               rcRect.bottom = rcRect.top + pParams[5].iValue;
               pNetDoc->m_pBitmapWindow->EnableCallBack(TRUE);
               nStatus = pNetDoc->m_pBitmapWindow->ZoomToRect(rcRect);
            }
            return pMain->m_Inet.SendSetRectRsp (plConnection, uCommandID,0,0,nStatus);
         }
      }
         
      return pMain->m_Inet.SendRsp (
            plConnection,
            uCommand,
            uCommandID,
            NULL,
            nStatus
            );
}