提交 f2d6b246 编写于 作者: Y yang-qibo

dsoftbus_ipc服务端代码开源

Signed-off-by: Nyang-qibo <yangqibo1@huawei.com>
上级 061ef18c
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos_var.gni")
group("communication") {
testonly = true
if (is_standard_system) {
deps = [
"bluetooth_ble:ActsBluetoothBleJsTest",
"bluetooth_on:ActsBluetoothOnJsTest",
"bluetooth_profile:ActsBluetoothProFileJsTest",
"bluetooth_standard:ActsBluetoothJsTest",
"dsoftbus/rpc:ActsRpcJsTest",
"dsoftbus/rpc_server:ActsRpcJsServer",
"wifi_p2p:ActsP2PJSTest",
"wifi_standard:ActsWifiJSTest",
]
} else {
deps = [ "wifi_standard:ActsWifiJSTest" ]
}
}
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsRpcJsServer") {
hap_profile = "./src/main/config.json"
deps = [
":rpc_js_assets",
":rpc_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsRpcHapServer"
subsystem_name = "communication"
part_name = "ipc"
}
ohos_js_assets("rpc_js_assets") {
source_dir = "./src/main/js"
hap_profile = "./src/main/config.json"
}
ohos_resources("rpc_js_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for rpc Servers",
"driver": {
"type": "JSUnitServer",
"test-timeout": "900000",
"package": "ohos.rpc.test.server",
"abilityName": ".MainAbility",
"shell-timeout": "900000"
},
"kits": [
{
"test-file-name": [
"ActsRpcHapServer.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "ohos.rpc.test.server",
"vendor": "rpc",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"target": 8
}
},
"deviceConfig": {},
"module": {
"reqPermissions": [
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
},
{
"name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO"
}
],
"package": "ohos.rpc.test.server",
"name": ".MyApplication",
"mainAbility": ".MainAbility",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "js",
"icon": "$media:icon",
"description": "$string:mainability_description",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
},
{
"srcPath": "ServiceAbility",
"name": ".ServiceAbility",
"icon": "$media:icon",
"srcLanguage": "js",
"description": "$string:serviceability_description",
"type": "service",
"visible": true,
"formsEnabled": false
}
],
"js": [
{
"pages": [
"pages/index/index",
"pages/second/second"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
onCreate() {
console.info("Application onCreate");
},
onDestroy() {
console.info("Application onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World",
"page": "Second Page",
"next": "Next Page",
"back": "Back"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界",
"page": "第二页",
"next": "下一页",
"back": "返回"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
.btn {
width: 50%;
height: 100px;
font-size: 40px;
}
<div class="container" onswipe="touchMove">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
<input class="btn" type="button" value="{{ $t('strings.next') }}" onclick="onclick"></input>
</div>
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router'
import featureAbility from '@ohos.ability.featureAbility';
export default {
data: {
title: ""
},
onInit() {
this.grantPermission();
},
onclick: function () {
router.replace({
uri: "pages/second/second"
})
},
grantPermission() {
console.info('Calc[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
})
},
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
.btn {
width: 50%;
height: 100px;
font-size: 40px;
}
<div class="container">
<text class="title">
{{ $t('strings.page') }}
</text>
<input class="btn" type="button" value="{{ $t('strings.back') }}" onclick="onclick"></input>
</div>
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router'
export default {
data: {
title: 'World'
},
onclick: function () {
router.replace({
uri: "pages/index/index"
})
}
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import rpc from "@ohos.rpc"
import fileio from '@ohos.fileio';
import process from '@ohos.process'
export default {
onStart() {
console.info('RpcServer: onStart')
},
onStop() {
console.info('RpcServer: onStop')
},
onCommand(want, startId) {
console.info('RpcServer: onCommand, want: ' + JSON.stringify(want) +', startId: ' + startId)
},
onConnect(want) {
console.info('RpcServer: service onConnect called.')
return new Stub("rpcTestAbility")
},
onDisconnect(want) {
console.info('RpcServer: service onDisConnect called.')
},
onReconnect(want) {
console.info('RpcServer: service onReConnect called.')
}
}
class MySequenceable {
num = null
str = null
constructor(num, string) {
this.num = num;
this.str = string;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
messageParcel.writeString(this.str);
return true;
}
unmarshalling(messageParcel) {
this.num = messageParcel.readInt();
this.str = messageParcel.readString();
return true;
}
}
class Stub extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
}
onRemoteRequest(code, data, reply, option) {
try{
console.info("onRemoteRequest: " + code)
console.info("-----------------syhsyhsysh:" + code)
switch(code) {
case 1:
{
console.info("case 1 start")
let tmp1 = data.readByteArray()
let result = reply.writeByteArray(tmp1)
return true
}
case 2:
{
console.info("case 2 start")
let tmp1 = data.readIntArray()
let result = reply.writeIntArray(tmp1)
return true
}
case 3:
{
console.info("case 3 start")
let tmp1 = data.readFloatArray()
let result = reply.writeFloatArray(tmp1)
return true
}
case 4:
{
console.info("case 4 start")
let tmp1 = data.readShort()
let result = reply.writeShort(tmp1)
return true
}
case 5:
{
console.info("case 5 start")
let tmp1 = data.readLong()
let result = reply.writeLong(tmp1)
return true
}
case 6:
{
console.info("case 6 start")
let tmp1 = data.readDouble()
let result = reply.writeDouble(tmp1)
return true
}
case 7:
{
console.info("case 7 start")
let tmp1 = data.readBoolean()
let result = reply.writeBoolean(tmp1)
return true
}
case 8:
{
console.info("case 8 start")
let tmp1 = data.readChar()
let result = reply.writeChar(tmp1)
return true
}
case 9:
{
console.info("case 9 start")
let tmp1 = data.readString()
let result = reply.writeString(tmp1)
return true
}
case 10:
{
console.info("case 10 start")
let tmp1 = data.readByte()
let result = reply.writeByte(tmp1)
return true
}
case 11:
{
console.info("case 11 start")
let tmp1 = data.readInt()
let result = reply.writeInt(tmp1)
return true
}
case 12:
{
console.info("case 12 start")
let tmp1 = data.readFloat()
let result = reply.writeFloat(tmp1)
return true
}
case 13:
{
console.info("case 13 start")
var size = data .readInt();
let tmp1 = data.readRawData(size);
let size1 = reply.writeInt(size);
let result = reply.writeRawData(tmp1, tmp.length)
return true
}
case 14:
{
console.info("case 14 start")
let listener = data.readRemoteObject();
let num = data.readInt()
let str = data.readString()
let option2 = new rpc.MessageOption()
let data2 = rpc.MessageParcel.create()
let reply2 = rpc.MessageParcel.create()
data2.writeInt(num)
data2.writeString(str)
listener.sendRequest(1, data2, reply2, option2)
.then(function(result) {
console.info("send request done, error code: " + result.errCode )
})
.catch(function(e) {
console.error("send request got exception: " + e)
})
.finally(() => {
data2.reclaim()
reply2.reclaim()
console.info("case 14 test done")
})
reply.writeNoException()
return true
}
case 15:
{
console.info("case 15 start")
let s = new MySequenceable(null, null)
var tmp1 = data.readSequenceable(s)
let result = reply.writeSequenceable(s)
return true
}
case 16:
{
console.info("case 16 start")
data.readException()
var tmp = data.readInt();
reply.writeNoException()
var result = reply.writeInt(tmp);
return true
}
case 17:
{
console.info("case 17 start")
var s = [new MySequenceable(null, null), new MySequenceable(null, null),
new MySequenceable(null, null)];
data.readSequenceableArray(s);
let result = reply.writeSequenceableArray(s);
return true
}
case 18:
{
console.info("case 18 start")
let listeners = data.readRemoteObjectArray();
for (let i = 0; i < listeners.length; i++) {
let option2 = new rpc.MessageOption()
let data2 = rpc.MessageParcel.create()
let reply2 = rpc.MessageParcel.create()
listeners[i].sendRequest(1, data2, reply2, option2)
.then(function(result) {
console.info("send request done, error code: " + result.errCode + ", index: " + i)
})
.catch(function(e) {
console.error("send request got exception: " + e)
})
.finally(() => {
data2.reclaim()
reply2.reclaim()
console.info("case 18 test done")
})
}
console.info("The server's writeRemoteObjectArray result is " + result);
return true
}
case 19:
{
console.info("case 19 start")
let tmp1 = data.readDoubleArray()
let result = reply.writeDoubleArray(tmp1)
return true
}
case 20:
{
console.info("case 20 start")
let tmp1 = data.readByte()
let tmp2 = data.readShort()
let tmp3 = data.readInt()
let tmp4 = data.readLong()
let tmp5 = data.readFloat()
let tmp6 = data.readDouble()
let tmp7 = data.readBoolean()
let tmp8 = data.readChar()
let tmp9 = data.readString()
let s = new MySequenceable(null, null)
let tmp10 = data.readSequenceable(s)
let result1 = reply.writeByte(tmp1)
let result2 = reply.writeShort(tmp2)
let result3 = reply.writeInt(tmp3)
let result4 = reply.writeLong(tmp4)
let result5 = reply.writeFloat(tmp5)
let result6 = reply.writeDouble(tmp6)
let result7 = reply.writeBoolean(tmp7)
let result8 = reply.writeChar(tmp8)
let result9 = reply.writeString(tmp9)
let result10 = reply.writeSequenceable(s)
return true
}
case 21:
{
console.info("case 21 start")
let tmp1 = data.readByteArray()
let tmp2 = data.readShortArray()
let tmp3 = data.readIntArray()
let tmp4 = data.readLongArray()
let tmp5 = data.readFloatArray()
let tmp6 = data.readDoubleArray()
let tmp7 = data.readBooleanArray()
let tmp8 = data.readCharArray()
let tmp9 = data.readStringArray()
let s = [new MySequenceable(null, null), new MySequenceable(null, null),
new MySequenceable(null, null)]
let tmp10 = data.readSequenceableArray(s)
let result1 = reply.writeByteArray(tmp1)
let result2 = reply.writeShortArray(tmp2)
let result3 = reply.writeIntArray(tmp3)
let result4 = reply.writeLongArray(tmp4)
let result5 = reply.writeFloatArray(tmp5)
let result6 = reply.writeDoubleArray(tmp6)
let result7 = reply.writeBooleanArray(tmp7)
let result8 = reply.writeCharArray(tmp8)
let result9 = reply.writeStringArray(tmp9)
let result10 = reply.writeSequenceableArray(s)
return true
}
case 22:
{
console.info("case 22 start")
let callingPid = rpc.IPCSkeleton.getCallingPid()
let callingUid = rpc.IPCSkeleton.getCallingUid()
reply.writeNoException()
reply.writeInt(callingPid)
reply.writeInt(callingUid)
reply.writeInt(this.getCallingPid())
reply.writeInt(this.getCallingUid())
let id = rpc.IPCSkeleton.resetCallingIdentity()
rpc.IPCSkeleton.setCallingIdentity(id)
reply.writeInt(rpc.IPCSkeleton.getCallingPid())
reply.writeInt(rpc.IPCSkeleton.getCallingUid())
reply.writeInt(rpc.IPCSkeleton.flushCommands(this))
return true
}
case 23:
{
console.info("case 23 start")
let s = new MySequenceable(null, null);
var tmp1 = data.readSequenceable(s);
var result = reply.writeSequenceable(s);
return true
}
case 24:
{
console.info("case 24 start")
var tmp1 = data.readShort();
var tmp2 = data.readShort();
var tmp3 = data.readShort();
var tmp4 = data.readShort();
var tmp5 = data.readShort();
var result1 = reply.writeShort(tmp1);
var result2 = reply.writeShort(tmp2);
var result3 = reply.writeShort(tmp3);
var result4 = reply.writeShort(tmp4);
var result5 = reply.writeShort(tmp5);
return true
}
case 25:
{
console.info("case 25 start")
var tmp1 = data.readByte();
var tmp2 = data.readByte();
var tmp3 = data.readByte();
var tmp4 = data.readByte();
var tmp5 = data.readByte();
var result1 = reply.writeByte(tmp1);
var result2 = reply.writeByte(tmp2);
var result3 = reply.writeByte(tmp3);
var result4 = reply.writeByte(tmp4);
var result5 = reply.writeByte(tmp5);
return true
}
case 26:
{
console.info("case 26 start")
var tmp1 = data.readInt();
var tmp2 = data.readInt();
var tmp3 = data.readInt();
var tmp4 = data.readInt();
var tmp5 = data.readInt();
var result1 = reply.writeInt(tmp1);
var result2 = reply.writeInt(tmp2);
var result3 = reply.writeInt(tmp3);
var result4 = reply.writeInt(tmp4);
var result5 = reply.writeInt(tmp5);
return true
}
case 28:
{
console.info("case 28 start")
let callingPid = rpc.IPCSkeleton.getCallingPid()
let callingUid = rpc.IPCSkeleton.getCallingUid()
let callingDeviceID = rpc.IPCSkeleton.getCallingDeviceID()
let localDeviceID = rpc.IPCSkeleton.getLocalDeviceID()
let isLocalCalling = rpc.IPCSkeleton.isLocalCalling()
reply.writeNoException()
reply.writeInt(callingPid)
reply.writeInt(callingUid)
reply.writeString(callingDeviceID)
reply.writeString(localDeviceID)
reply.writeBoolean(isLocalCalling)
reply.writeInt(this.getCallingPid())
reply.writeInt(this.getCallingUid())
let id = rpc.IPCSkeleton.resetCallingIdentity()
rpc.IPCSkeleton.setCallingIdentity(id)
reply.writeInt(rpc.IPCSkeleton.getCallingPid())
reply.writeInt(rpc.IPCSkeleton.getCallingUid())
reply.writeInt(rpc.IPCSkeleton.flushCommands(this))
return true
}
case 29:
{
console.info("case 29 starts")
let bytesWr = data.readInt()
let fd = data.readFileDescriptor()
let writeFileResult = fileio.writeSync(fd, "HELLO RPC", {position: bytesWr + 1});
rpc.MessageParcel.closeFileDescriptor(fd)
return true
}
case 30:
{
console.info("case 30 start")
let listeners = data.readRemoteObjectArray();
let num = data.readInt()
let str = data.readString()
for (let i = 0; i < listeners.length; i++) {
let option2 = new rpc.MessageOption()
let data2 = rpc.MessageParcel.create()
let reply2 = rpc.MessageParcel.create()
data2.writeInt(num)
data2.writeString(str)
listeners[i].sendRequest(1, data2, reply2, option2)
.then(function(result) {
console.info("send request done, error code: " + result.errCode + ", index: " + i)
})
.catch(function(e) {
console.error("send request got exception: " + e)
})
.finally(() => {
data2.reclaim()
reply2.reclaim()
console.info("case 30 test done")
})
}
reply.writeNoException()
return true
}
case 31:
{
console.info("case 31 start")
let listeners = new Array(3)
data.readRemoteObjectArray(listeners)
let num = data.readInt()
let str = data.readString()
for (let i = 0; i < listeners.length; i++) {
let option2 = new rpc.MessageOption()
let data2 = rpc.MessageParcel.create()
let reply2 = rpc.MessageParcel.create()
data2.writeInt(num)
data2.writeString(str)
listeners[i].sendRequest(1, data2, reply2, option2)
.then(function(result) {
console.info("send request done, error code: " + result.errCode + ", index: " + i)
})
.catch(function(e) {
console.error("send request got exception: " + e)
})
.finally(() => {
data2.reclaim()
reply2.reclaim()
console.info("case 31 test done")
})
}
reply.writeNoException()
return true
}
default:
console.error("default case " + code)
return super.onRemoteRequest(code, data, reply, option)
}
} catch (error) {
console.info("onRemoteRequest: " + error);
}
return false
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
[ZoneTransfer]
ZoneId=1
ReferrerUrl=vscode-file://vscode-app/d:/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html
HostUrl=file:///z%3A/home/yqb/openharmony/master/test/xts/acts/communication/dsoftbus/rpc_server/Test.json
{
"string": [
{
"name": "entry_MainAbility",
"value": "RpcServer"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
},
{
"name": "serviceability_description",
"value": "hap sample empty service"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册