By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,505 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,505 IT Pros & Developers. It's quick & easy.

Can anyone please outline whatz happening in this code .

P: 11
Hi Mates, Can u please tell me whats happpenning in those. Please tell what ever u got. Outline the functinaliy in normal words. i am new to C++. I need to write SWIG wrapper which checks this C++ Code in perl.

Please tell , what ever u understood .

Thanks in advance


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include "stdafx.h"
  3. #include "client.h"
  4. using namespace std;
  5.  
  6. int main(int argc, char* argv[])
  7. {
  8.     char szKey[48];
  9.     Key k;
  10.     Block *b;
  11.     int total;
  12.     TransferResult ret;
  13.     //printf("%d", argc);
  14.     if ((argc == 8) || (argc == 9))
  15.     {
  16.         str_to_key(argv[2], k);
  17.         if (strcmp(argv[1],"-put") == 0)
  18.         {
  19.             total = HEADER_SIZE(Block) + atoi(argv[3]);
  20.             b = (Block *) MALLOC(void, total);
  21.             b->size = atoi(argv[3]);
  22.             memcpy(b->data, argv[4], b->size);
  23.         }
  24.     }
  25.     else
  26.     {
  27.         cout << "Usage:" << endl;
  28.         cout << "    FakeFEClient.exe -p <key> <value>" << endl;
  29.         cout << "    FakeFEClient.exe -g <key>" << endl;
  30.         return 0;
  31.     }
  32.  
  33.  
  34.     try {
  35.  
  36.         Client *c;
  37.  
  38.         if (strcmp(argv[1],"-get") == 0)
  39.             c = new Client(argv[5], atoi(argv[7]));
  40.         else
  41.             c = new Client(argv[6], atoi(argv[8]));
  42.  
  43.  
  44.         key_to_str(k, szKey, sizeof(szKey));
  45.  
  46.  
  47.         if (strcmp(argv[1],"-put") == 0)
  48.         {
  49.             ret = c->PutBlock(k, b,10000);
  50.             if (ret == TR_Processed)
  51.             {
  52.                 cout << "Put operation successful";
  53.             }
  54.             else
  55.             {
  56.                 cout << "Put operation failed";
  57.             }
  58.             free(b);
  59.         }
  60.  
  61.         if (strcmp(argv[1],"-get") == 0)
  62.         {
  63.             byte block_buf[BLOCK_BUF_LIMIT];
  64.             Block* block = (Block*)block_buf;
  65.             block->size = atoi(argv[3]);
  66.             ret = c->GetBlock(k, block, 1000);
  67.             if (ret != TR_Processed)
  68.             {
  69.                 cout << "Get operation failed";
  70.                 return 1;
  71.             }
  72.             block->data[block->size]='\0';
  73.             printf("%s",block->data);
  74.         }
  75.  
  76.  
  77.     }
  78.     catch (NetworkException e)
  79.     {
  80.         std::cout << "Network exception raised" << std::endl;
  81.     }
  82.     catch (...)
  83.     {
  84.         std::cout << "Exception raised" << std::endl; 
  85.     }
  86.  
  87.     return 0;
  88. }
  89.  
  90.  
Nov 13 '08 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
The person who wrote this is also new to C++ because the code is largely C.

I would suggest you locate the author and ask what the code does.

I could help if you had a specific question but not when what you ask is really not a question at all but is a request for a consultation.
Nov 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.