|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "serviceclasshandler.h" |
|
20 #include "applicationinfo.h" |
|
21 #include "comms.h" |
|
22 #include "logger.h" |
|
23 |
|
24 using namespace java::bluetooth; |
|
25 using namespace java::comms; |
|
26 |
|
27 |
|
28 /* |
|
29 * If aSrvClassVal equals 0, then it is assumed that midlet gets closed. |
|
30 */ |
|
31 |
|
32 OS_EXPORT int ServiceClassHandler::setDeviceServiceClass( |
|
33 unsigned int aSrvClassVal, bool aIsServiceBitsPersistent) |
|
34 { |
|
35 JELOG2(EJavaBluetooth); |
|
36 |
|
37 // Send message to set the service class value |
|
38 LOG1( |
|
39 EJavaBluetooth, |
|
40 EInfo, |
|
41 " ServiceClassHandler::setDeviceServiceClass setting serviceClass:0x%X", |
|
42 aSrvClassVal); |
|
43 |
|
44 CommsMessage msg; |
|
45 msg.setModuleId(PLUGIN_ID_BT_DEVICE_CLASS_MANAGER_C); |
|
46 msg.setMessageId(JSR_82_MESSAGE_ID_RANGE_START_C); |
|
47 msg << (int) aIsServiceBitsPersistent; |
|
48 msg << getMidletId(); |
|
49 msg << (int) aSrvClassVal; |
|
50 return sendMsg(msg); |
|
51 } |
|
52 |
|
53 std::wstring ServiceClassHandler::getMidletId() |
|
54 { |
|
55 JELOG2(EJavaBluetooth); |
|
56 const java::runtime::ApplicationInfo& appInf = |
|
57 java::runtime::ApplicationInfo::getInstance(); |
|
58 const java::util::Uid &uid = appInf.getUid(); |
|
59 LOG1(EJavaBluetooth, EInfo, |
|
60 "- ServiceClassHandler::getMidletId MidletID:%S", |
|
61 uid.toString().c_str()); |
|
62 return uid.toString(); |
|
63 } |
|
64 |
|
65 int ServiceClassHandler::sendMsg(CommsMessage aMsg) |
|
66 { |
|
67 JELOG2(EJavaBluetooth); |
|
68 |
|
69 CommsClientEndpoint comms; |
|
70 int rc = comms.connect(IPC_ADDRESS_JAVA_CAPTAIN_C); |
|
71 if (rc != 0) |
|
72 { |
|
73 ELOG1( |
|
74 EJavaBluetooth, |
|
75 "- ServiceClassHandler::sendMsg Comm connection failed! Err:%d", |
|
76 rc); |
|
77 return -1; |
|
78 } |
|
79 |
|
80 CommsMessage recvMsg; |
|
81 |
|
82 rc = comms.sendReceive(aMsg, recvMsg, WAIT_FOR_EVER); |
|
83 if (rc!=0) |
|
84 { |
|
85 ELOG1( |
|
86 EJavaBluetooth, |
|
87 "- ServiceClassHandler::sendMsg sendReceive failed! Err:%d", |
|
88 rc); |
|
89 return -1; |
|
90 } |
|
91 int retVal; |
|
92 recvMsg >> retVal; |
|
93 |
|
94 comms.disconnect(); |
|
95 |
|
96 return retVal; |
|
97 } |