author | hgs |
Fri, 29 Oct 2010 11:49:32 +0300 | |
changeset 87 | 1627c337e51e |
parent 21 | 2a9601315dfc |
permissions | -rw-r--r-- |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
* Description: This class implements Comms client endpoint. Client |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
* endpoint can be connected to server endpoint and it forwards |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
#include <time.h> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
#include <errno.h> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
#include <string> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
#include "logger.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
#include "commsclientendpoint.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
#include "comms.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
#include "commsmessage.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
#include "commscontext.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
namespace java |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
32 |
namespace comms |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
OS_EXPORT CommsClientEndpoint::CommsClientEndpoint(): mAddress(0), mAddedToContext(false) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
JELOG2(EJavaComms); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
mIpc.reset(IpcConnectionFactory::createConnection(this)); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
42 |
OS_EXPORT CommsClientEndpoint::CommsClientEndpoint(const std::wstring& aName): mAddress(0), mAddedToContext(true) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
JELOG2(EJavaComms); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
mIpc.reset(IpcConnectionFactory::createConnection(this)); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
CommsContext::getContext().add(this, aName); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
OS_EXPORT CommsClientEndpoint::~CommsClientEndpoint() |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
51 |
JELOG2(EJavaComms); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
52 |
disconnect(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
53 |
// avoid creating context when not needed |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
54 |
if (mAddedToContext) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
55 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
CommsContext::getContext().remove(this); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
OS_EXPORT CommsClientEndpoint* CommsClientEndpoint::find(const std::wstring& aName) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
61 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
JELOG2(EJavaComms); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
return CommsContext::getContext().find(aName); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
65 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
OS_EXPORT int CommsClientEndpoint::connect(int aAddress) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
JELOG2(EJavaComms); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
mAddress = aAddress; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
return mIpc->connect(aAddress); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
71 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
72 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
OS_EXPORT int CommsClientEndpoint::disconnect() |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
74 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
75 |
JELOG2(EJavaComms); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
76 |
mIpc->disconnect(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
77 |
return 0; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
79 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
80 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
81 |
OS_EXPORT int CommsClientEndpoint::send(CommsMessage& aMessage) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
83 |
JELOG2(EJavaComms); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
84 |
char* buf = aMessage.toByteArray(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
85 |
int rc = mIpc->send(reinterpret_cast<ipcMessage_t*>(buf)); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
86 |
return rc; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
89 |
|
87 | 90 |
OS_EXPORT int CommsClientEndpoint::detachFromVm(JNIEnv* aEnv) |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
91 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
92 |
JELOG2(EJavaComms); |
87 | 93 |
CommsEndpoint::detachFromVm(aEnv); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
95 |
int rc = disconnect(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
96 |
rc = connect(mAddress); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
97 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
98 |
return rc; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
99 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
100 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
101 |
} // namespace comms |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
102 |
} // namespace java |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
103 |