clientinterface.cpp File Reference

#include <clientinterface.h>
#include <extern.h>
#include <math.h>
#include <iostream>
#include <stdio.h>
#include "../interface/RioError.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

Go to the source code of this file.

Functions

void SendComplete (void *Param, int Result)
void ReceiveComplete (void *Param, int Result)

Function Documentation

void ReceiveComplete ( void *  Param,
int  Result 
)

Definition at line 148 of file clientinterface.cpp.

00149 {
00150     #ifdef RIO_DEBUG1
00151     RioErr << "[ClientInterface - ReceiveComplete] Start" << endl;
00152     #endif
00153     StrRequest* Request = (StrRequest*) Param;
00154     int FlagStatus;
00155     u16 Command = Request->Command;
00156 
00157     // Test if receiving data from client requires
00158     // a status message to be sent to router.
00159     if( ( Command & 0xf ) == MSG_RSS_WRITE )
00160     {
00161         #ifdef RIO_DEBUG2
00162         RioErr << "[ClientInterface - ReceiveComplete] Command: Write" << endl;
00163         #endif
00164         // if command is "write" this is the first of two steps
00165         // Send status message only if bit RSS_INTERMEDIATE is set
00166         if( Command & RSS_INTERMEDIATE )
00167             FlagStatus = 1;
00168         else
00169             FlagStatus = 0;
00170     }
00171     else
00172     {
00173         #ifdef RIO_DEBUG2
00174         RioErr << "[ClientInterface - ReceiveComplete] Command: Receive" << endl;
00175         #endif
00176         // If request is not "write" it should be "receive" (one step command)
00177         // Send status message if bit RSS_NOCOMPLETE is not set
00178         if( ( Command & RSS_NOCOMPLETE ) && ( Result == 0 ))
00179             FlagStatus = 0;
00180         else
00181             FlagStatus = 1;
00182     }
00183 
00184     // Reset flag bits on command
00185     Command = Command & 0xf;
00186 
00187     // Update request status
00188     if( Command == MSG_RSS_RECEIVE )
00189     {
00190         Request->Status = RequestStatusWaitFlushCommand;
00191     }
00192     else
00193     {
00194         Request->Status = RequestStatusReceiveDone;
00195     }
00196 
00197     StrMsg* Slot = NULL;
00198 
00199     // Prepare status message to router if required
00200     if( FlagStatus )
00201     {
00202         #ifdef RIO_DEBUG2
00203         RioErr << "[ClientInterface - ReceiveComplete] Preparing status message to router" << endl;
00204         #endif
00205         // Get a router message slot and fill message fields
00206         Slot = MsgManager.New();
00207         Slot->Msg.Storage.Status.Type          = MSG_RSS_RECEIVECOMPLETE;
00208         Slot->Msg.Storage.Status.Size          = SizeMsgRSSstatus;
00209         Slot->Msg.Storage.Status.RouterId      = Request->RouterId;
00210         Slot->Msg.Storage.Status.StorageId     = Request->Id;
00211         Slot->Msg.Storage.Status.ActiveThreads = 0;
00212         // --------------------------------------------------------------------
00213         if( Result == 0 )
00214             Slot->Msg.Storage.Status.Error     = 0;
00215         else
00216             Slot->Msg.Storage.Status.Error     = ERROR_RSS_RECEIVE_FAILED;
00217     }
00218 
00219     if( Result != 0 )
00220     {
00221         #ifdef RIO_DEBUG2
00222         struct in_addr clientip;
00223         clientip.s_addr = Request->IPaddress;
00224         RioErr << "clientinterface.ReceiveComplete - bad result : "
00225                << (int *) Result
00226                << " " << (unsigned int) Result
00227                << " : Reqid  " << Request->ClientId
00228                << " IP "       << inet_ntoa(clientip)
00229                << " Port "     << ntohs( Request->Port )
00230                << endl;
00231         #endif
00232 
00233         // If receive failed Free request
00234         RequestManager.Free(Request);
00235     }
00236 
00237     // Send status message to router if required
00238     if( FlagStatus )
00239     {
00240         #ifdef RIO_DEBUG2
00241         RioErr << "[ClientInterface - ReceiveComplete] Sending status message "
00242                << "to router" << endl;
00243         #endif
00244 
00245         Router.Send(Slot);
00246     }
00247 
00248     if( Result == 0 )
00249     {
00250         // For write command send data to device
00251         if( Command == MSG_RSS_WRITE )
00252         {
00253             #ifdef RIO_DEBUG2
00254             RioErr << "[ClientInterface - ReceiveComplete] Sending data to device" << endl;
00255             #endif
00256             Device[Request->Disk].ProcessRequest(Request);
00257         }
00258     }
00259     #ifdef RIO_DEBUG1
00260     RioErr << "[ClientInterface - ReceiveComplete] Finish" << endl;
00261     #endif
00262 }

void SendComplete ( void *  Param,
int  Result 
)

Definition at line 82 of file clientinterface.cpp.

00083 {
00084     StrRequest* Request = (StrRequest*) Param;
00085 
00086     int FlagStatus;
00087     u16 Command = Request->Command;
00088 
00089     if( Result )
00090     {
00091         struct in_addr clientip;
00092         clientip.s_addr = Request->IPaddress;
00093         RioErr << "clientinterface.SendComplete - bad result : "
00094                << (int *) Result
00095                << " " << (unsigned int) Result
00096                << " : Reqid  " << Request->ClientId
00097                << " IP "       << inet_ntoa(clientip)
00098                << " Port "     << ntohs( Request->Port )
00099                << endl;
00100     }
00101 
00102     // Test if sending data to client requires a
00103     // status message to be sent to router.
00104     // Send status message if bit RSS_NOCOMPLETE is not set
00105     if( ( Command & RSS_NOCOMPLETE ) && ( Result == 0 ))
00106         FlagStatus = 0;
00107     else
00108         FlagStatus = 1;
00109 
00110     StrMsg* Slot = NULL;
00111 
00112     u32 temp;
00113 
00114     // If required prepare a message to be sent to router
00115     if( FlagStatus )
00116     {
00117         // Get a router message slot and fill message fields
00118         Slot = MsgManager.New();
00119         Slot->Msg.Storage.Status.Type          = MSG_RSS_SENDCOMPLETE;
00120         Slot->Msg.Storage.Status.Size          = SizeMsgRSSstatus;
00121         Slot->Msg.Storage.Status.RouterId      = Request->RouterId;
00122         Slot->Msg.Storage.Status.StorageId     = Request->Id;
00123         Slot->Msg.Storage.Status.ActiveThreads = 0;
00124         // --------------------------------------------------------------------
00125         if( Result == 0 )
00126             Slot->Msg.Storage.Status.Error     = 0;
00127         else
00128             Slot->Msg.Storage.Status.Error     = ERROR_RSS_SEND_FAILED;
00129         temp = Request->Id;
00130     }
00131 
00132     // Free request
00133     RequestManager.Free( Request );
00134 
00135     // If required send status message to router
00136     if( FlagStatus )
00137     {
00138         #ifdef RIO_DEBUG2
00139         RioErr <<"Sending status (SEND COMPLETE) to router " << endl;
00140         #endif
00141 
00142         Router.Send(Slot);
00143     }
00144 }

Generated on Wed Jul 4 16:03:29 2012 for RIO by  doxygen 1.6.3