javacommons/comms/src/commsserverendpoint.cpp
changeset 21 2a9601315dfc
child 87 1627c337e51e
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 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:  This class implements Comms server endpoint. Server
       
    15 *                endpoint waits for incoming connections and it forwards
       
    16 *
       
    17 */
       
    18 
       
    19 #include "logger.h"
       
    20 
       
    21 #include "commsserverendpoint.h"
       
    22 #include "commsmessage.h"
       
    23 #include "commscontext.h"
       
    24 
       
    25 namespace java
       
    26 {
       
    27 namespace comms
       
    28 {
       
    29 
       
    30 OS_EXPORT CommsServerEndpoint::CommsServerEndpoint() : mAddress(0), mAddedToContext(false)
       
    31 {
       
    32     JELOG2(EJavaComms);
       
    33     mIpc.reset(IpcConnectionFactory::createServerConnection(this));
       
    34 }
       
    35 
       
    36 OS_EXPORT CommsServerEndpoint::CommsServerEndpoint(const std::wstring& aName): mAddress(0), mAddedToContext(true)
       
    37 {
       
    38     JELOG2(EJavaComms);
       
    39     mIpc.reset(IpcConnectionFactory::createServerConnection(this));
       
    40     CommsContext::getContext().add(this, aName);
       
    41 }
       
    42 
       
    43 OS_EXPORT CommsServerEndpoint::~CommsServerEndpoint()
       
    44 {
       
    45     JELOG2(EJavaComms);
       
    46     stop();
       
    47     // avoid creating context when not needed
       
    48     if (mAddedToContext)
       
    49     {
       
    50         CommsContext::getContext().remove(this);
       
    51     }
       
    52 }
       
    53 
       
    54 OS_EXPORT CommsServerEndpoint* CommsServerEndpoint::find(const std::wstring& aName)
       
    55 {
       
    56     JELOG2(EJavaComms);
       
    57     return CommsContext::getContext().findServer(aName);
       
    58 }
       
    59 
       
    60 OS_EXPORT int CommsServerEndpoint::start(int aAddress)
       
    61 {
       
    62     JELOG2(EJavaComms);
       
    63     mAddress = aAddress;
       
    64     return mIpc->start(aAddress);
       
    65 }
       
    66 
       
    67 OS_EXPORT int CommsServerEndpoint::stop()
       
    68 {
       
    69     JELOG2(EJavaComms);
       
    70     mIpc->stop();
       
    71     return 0;
       
    72 }
       
    73 
       
    74 OS_EXPORT int CommsServerEndpoint::send(CommsMessage& aMessage)
       
    75 {
       
    76     JELOG2(EJavaComms);
       
    77     char* buf = aMessage.toByteArray();
       
    78     int rc =  mIpc->send(reinterpret_cast<ipcMessage_t*>(buf));
       
    79     return rc;
       
    80 }
       
    81 
       
    82 OS_EXPORT int CommsServerEndpoint::detachFromVm()
       
    83 {
       
    84     JELOG2(EJavaComms);
       
    85     CommsEndpoint::detachFromVm();
       
    86 
       
    87     int rc = stop();
       
    88     rc = start(mAddress);
       
    89 
       
    90     return rc;
       
    91 }
       
    92 
       
    93 } // namespace comms
       
    94 } // namespace java
       
    95 
       
    96