|
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 client endpoint. Client |
|
15 * endpoint can be connected to server endpoint and it forwards |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <time.h> |
|
20 #include <errno.h> |
|
21 #include <string> |
|
22 |
|
23 #include "logger.h" |
|
24 |
|
25 #include "commsclientendpoint.h" |
|
26 #include "comms.h" |
|
27 #include "commsmessage.h" |
|
28 #include "commscontext.h" |
|
29 |
|
30 namespace java |
|
31 { |
|
32 namespace comms |
|
33 { |
|
34 |
|
35 |
|
36 OS_EXPORT CommsClientEndpoint::CommsClientEndpoint(): mAddress(0), mAddedToContext(false) |
|
37 { |
|
38 JELOG2(EJavaComms); |
|
39 mIpc.reset(IpcConnectionFactory::createConnection(this)); |
|
40 } |
|
41 |
|
42 OS_EXPORT CommsClientEndpoint::CommsClientEndpoint(const std::wstring& aName): mAddress(0), mAddedToContext(true) |
|
43 { |
|
44 JELOG2(EJavaComms); |
|
45 mIpc.reset(IpcConnectionFactory::createConnection(this)); |
|
46 CommsContext::getContext().add(this, aName); |
|
47 } |
|
48 |
|
49 OS_EXPORT CommsClientEndpoint::~CommsClientEndpoint() |
|
50 { |
|
51 JELOG2(EJavaComms); |
|
52 disconnect(); |
|
53 // avoid creating context when not needed |
|
54 if (mAddedToContext) |
|
55 { |
|
56 CommsContext::getContext().remove(this); |
|
57 } |
|
58 } |
|
59 |
|
60 OS_EXPORT CommsClientEndpoint* CommsClientEndpoint::find(const std::wstring& aName) |
|
61 { |
|
62 JELOG2(EJavaComms); |
|
63 return CommsContext::getContext().find(aName); |
|
64 } |
|
65 |
|
66 OS_EXPORT int CommsClientEndpoint::connect(int aAddress) |
|
67 { |
|
68 JELOG2(EJavaComms); |
|
69 mAddress = aAddress; |
|
70 return mIpc->connect(aAddress); |
|
71 } |
|
72 |
|
73 OS_EXPORT int CommsClientEndpoint::disconnect() |
|
74 { |
|
75 JELOG2(EJavaComms); |
|
76 mIpc->disconnect(); |
|
77 return 0; |
|
78 } |
|
79 |
|
80 |
|
81 OS_EXPORT int CommsClientEndpoint::send(CommsMessage& aMessage) |
|
82 { |
|
83 JELOG2(EJavaComms); |
|
84 char* buf = aMessage.toByteArray(); |
|
85 int rc = mIpc->send(reinterpret_cast<ipcMessage_t*>(buf)); |
|
86 return rc; |
|
87 } |
|
88 |
|
89 |
|
90 OS_EXPORT int CommsClientEndpoint::detachFromVm() |
|
91 { |
|
92 JELOG2(EJavaComms); |
|
93 CommsEndpoint::detachFromVm(); |
|
94 |
|
95 int rc = disconnect(); |
|
96 rc = connect(mAddress); |
|
97 |
|
98 return rc; |
|
99 } |
|
100 |
|
101 } // namespace comms |
|
102 } // namespace java |
|
103 |