javacommons/comms/tsrc/src/utils/echoserver.h
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15  *
       
    16 */
       
    17 
       
    18 #ifndef ECHOSERVER_H
       
    19 #define ECHOSERVER_H
       
    20 
       
    21 #include "commslistener.h"
       
    22 #include "commsserverendpoint.h"
       
    23 #include "commsmessage.h"
       
    24 
       
    25 using namespace java::comms;
       
    26 
       
    27 const int MODULE_ID_NO_REPLY    = 100;
       
    28 const int MODULE_ID_ECHO        = 101;
       
    29 const int MODULE_ID_SLEEP_1S    = 1000;
       
    30 const int MODULE_ID_SLEEP_2S    = 2000;
       
    31 const int MODULE_ID_SLEEP_5S    = 5000;
       
    32 
       
    33 const int IPC_ADDRESS_COMMS_MODULE_TEST = 10321;
       
    34 
       
    35 class EchoServer : public CommsListener
       
    36 {
       
    37 public:
       
    38     EchoServer();
       
    39     virtual ~EchoServer();
       
    40 
       
    41     // CommsListener methods
       
    42     virtual void processMessage(CommsMessage& aMessage);
       
    43 
       
    44     int start(int addr);
       
    45     int stop();
       
    46 
       
    47     CommsEndpoint* getComms()
       
    48     {
       
    49         return &mComms;
       
    50     }
       
    51 
       
    52 private:
       
    53     CommsMessage mReply;
       
    54     CommsServerEndpoint mComms;
       
    55 };
       
    56 
       
    57 
       
    58 class EchoListener : public CommsListener
       
    59 {
       
    60 public:
       
    61     EchoListener(CommsEndpoint* comms)
       
    62     {
       
    63         mComms = comms;
       
    64     }
       
    65 
       
    66     virtual void processMessage(CommsMessage& message)
       
    67     {
       
    68         CommsMessage reply = message;
       
    69         reply.replyTo(message);
       
    70         mComms->send(reply);
       
    71 
       
    72     }
       
    73 private:
       
    74     CommsEndpoint* mComms;
       
    75 };
       
    76 
       
    77 std::string wstringToUtf8(const std::wstring& str);
       
    78 
       
    79 #endif // ECHOSERVER_H