DSoftBus Subsystem Changelog
Support for Exception Handling and Determining Synchronous or Asynchronous Message Sending by Passing in a Boolean or Numeric Value in IPC&RPC APIs
- Some IPC&RPC APIs of DSoftBus use service logic return values to indicate error information, which does not comply with the API error code specifications of OpenHarmony.
- A Boolean value can be passed in to specify the message transfer mode, which can be asynchronous or synchronous.
Change Impact
This version is compatible with earlier versions and no adaptation is required. Newly added APIs can be called to support the following changes:
- Implement exception handling and return of error codes.
- Enable messages to be sent synchronously or asynchronously by using a Boolean value or a number of 0 or non-0.
Key API/Component Changes
To ease the adaptation, the related IPC&RPC APIs are deprecated and replaced by new APIs. The newly added APIs support unified error code handling specifications and function the same as the original APIs.
Class | Deprecated API | New Class | New API |
---|---|---|---|
MessageParcel | static create(): MessageParcel | MessageSequence | static create(): MessageSequence |
MessageParcel | reclaim(): void | MessageSequence | reclaim(): void |
MessageParcel | writeRemoteObject(object: IRemoteObject): boolean | MessageSequence | writeRemoteObject(object: IRemoteObject): void |
MessageParcel | readRemoteObject(): IRemoteObject | MessageSequence | readRemoteObject(): IRemoteObject |
MessageParcel | writeInterfaceToken(token: string): boolean | MessageSequence | writeInterfaceToken(token: string): void |
MessageParcel | readInterfaceToken(): string | MessageSequence | readInterfaceToken(): string |
MessageParcel | getSize(): number | MessageSequence | getSize(): number |
MessageParcel | getCapacity(): number | MessageSequence | getCapacity(): number |
MessageParcel | setSize(size: number): boolean | MessageSequence | setCapacity(size: number): void |
MessageParcel | getReadableBytes(): number | MessageSequence | getReadableBytes(): number |
MessageParcel | getReadPosition(): number | MessageSequence | getReadPosition(): number |
MessageParcel | getWritePosition(): number | MessageSequence | getWritePosition(): number |
MessageParcel | rewindRead(pos: number): boolean | MessageSequence | rewindRead(pos: number): void |
MessageParcel | rewindWrite(pos: number): boolean | MessageSequence | rewindWrite(pos: number): void |
MessageParcel | writeNoException(): void | MessageSequence | writeNoException(): void |
MessageParcel | readException(): void | MessageSequence | readException(): void |
MessageParcel | writeByte(val: number): boolean | MessageSequence | writeByte(val: number): void |
MessageParcel | writeShort(val: number): boolean | MessageSequence | writeShort(val: number): void |
MessageParcel | writeInt(val: number): boolean | MessageSequence | writeInt(val: number): void |
MessageParcel | writeLong(val: number): boolean | MessageSequence | writeLong(val: number): void |
MessageParcel | writeFloat(val: number): boolean | MessageSequence | writeFloat(val: number): void |
MessageParcel | writeDouble(val: number): boolean | MessageSequence | writeDouble(val: number): void |
MessageParcel | writeBoolean(val: boolean): boolean | MessageSequence | writeBoolean(val: boolean): void |
MessageParcel | writeChar(val: number): boolean | MessageSequence | writeChar(val: number): void |
MessageParcel | writeString(val: string): boolean | MessageSequence | writeString(val: string): void |
MessageParcel | writeSequenceable(val: Sequenceable): boolean | MessageSequence | writeParcelable(val: Parcelable): void |
MessageParcel | writeByteArray(byteArray: number[]): boolean | MessageSequence | writeByteArray(byteArray: number[]): void |
MessageParcel | writeShortArray(shortArray: number[]): boolean | MessageSequence | writeShortArray(shortArray: number[]): void |
MessageParcel | writeIntArray(intArray: number[]): boolean | MessageSequence | writeIntArray(intArray: number[]): void |
MessageParcel | writeLongArray(longArray: number[]): boolean | MessageSequence | writeLongArray(longArray: number[]): void |
MessageParcel | writeFloatArray(floatArray: number[]): boolean | MessageSequence | writeFloatArray(floatArray: number[]): void |
MessageParcel | writeDoubleArray(doubleArray: number[]): boolean | MessageSequence | writeDoubleArray(doubleArray: number[]): void |
MessageParcel | writeBooleanArray(booleanArray: boolean[]): boolean | MessageSequence | writeBooleanArray(booleanArray: boolean[]): void |
MessageParcel | writeCharArray(charArray: number[]): boolean | MessageSequence | writeCharArray(charArray: number[]): void |
MessageParcel | writeStringArray(stringArray: string[]): boolean | MessageSequence | writeStringArray(stringArray: string[]): void |
MessageParcel | writeSequenceableArray(sequenceableArray: Sequenceable[]): boolean | MessageSequence | writeParcelableArray(sequenceableArray: Parcelable[]): void |
MessageParcel | writeRemoteObjectArray(objectArray: IRemoteObject[]): boolean | MessageSequence | writeRemoteObjectArray(objectArray: IRemoteObject[]): void |
MessageParcel | readByte(): number | MessageSequence | readByte(): number |
MessageParcel | readShort(): number | MessageSequence | readShort(): number |
MessageParcel | readLong(): number | MessageSequence | readLong(): number |
MessageParcel | readFloat(): number | MessageSequence | readFloat(): number |
MessageParcel | readDouble(): number | MessageSequence | readDouble(): number |
MessageParcel | readBoolean(): boolean | MessageSequence | readBoolean(): boolean |
MessageParcel | readChar(): number | MessageSequence | readChar(): number |
MessageParcel | readString(): string | MessageSequence | readString(): string |
MessageParcel | readSequenceable(dataIn: Sequenceable) : boolean | MessageSequence | readSequenceable(dataIn: Parcelable) : void |
MessageParcel | readByteArray(dataIn: number[]) : void | MessageSequence | readByteArray(dataIn: number[]) : void |
MessageParcel | readByteArray(): number[] | MessageSequence | readByteArray(): number[] |
MessageParcel | readShortArray(dataIn: number[]) : void | MessageSequence | readShortArray(dataIn: number[]) : void |
MessageParcel | readShortArray(): number[] | MessageSequence | readShortArray(): number[] |
MessageParcel | readIntArray(dataIn: number[]) : void | MessageSequence | readIntArray(dataIn: number[]) : void |
MessageParcel | readIntArray() : number[] | MessageSequence | readIntArray() : number[] |
MessageParcel | readLongArray(dataIn: number[]) : void | MessageSequence | readLongArray(dataIn: number[]) : void |
MessageParcel | readLongArray(): number[] | MessageSequence | readLongArray(): number[] |
MessageParcel | readFloatArray(dataIn: number[]) : void | MessageSequence | readFloatArray(dataIn: number[]) : void |
MessageParcel | readFloatArray(): number[] | MessageSequence | readFloatArray(): number[] |
MessageParcel | readDoubleArray(dataIn: number[]) : void | MessageSequence | readDoubleArray(dataIn: number[]) : void |
MessageParcel | readDoubleArray(): number[] | MessageSequence | readDoubleArray(): number[] |
MessageParcel | readBooleanArray(dataIn: boolean[]) : void | MessageSequence | readBooleanArray(dataIn: boolean[]) : void |
MessageParcel | readBooleanArray(): boolean[] | MessageSequence | readBooleanArray(): boolean[] |
MessageParcel | readCharArray(dataIn: number[]) : void | MessageSequence | readCharArray(dataIn: number[]) : void |
MessageParcel | readCharArray(): number[] | MessageSequence | readCharArray(): number[] |
MessageParcel | readStringArray(dataIn: string[]) : void | MessageSequence | readStringArray(dataIn: string[]) : void |
MessageParcel | readStringArray(): string[] | MessageSequence | readStringArray(): string[] |
MessageParcel | readSequenceableArray(sequenceableArray: Sequenceable[]): void | MessageSequence | readSequenceableArray(sequenceableArray: Parcelable[]): void |
MessageParcel | readRemoteObjectArray(objects: IRemoteObject[]): void | MessageSequence | readRemoteObjectArray(objects: IRemoteObject[]): void |
MessageParcel | readRemoteObjectArray(): IRemoteObject[] | MessageSequence | readRemoteObjectArray(): IRemoteObject[] |
MessageParcel | static closeFileDescriptor(fd: number): void | MessageSequence | static closeFileDescriptor(fd: number): void |
MessageParcel | static dupFileDescriptor(fd: number) :number | MessageSequence | static dupFileDescriptor(fd: number) :number |
MessageParcel | containFileDescriptors(): boolean | MessageSequence | containFileDescriptors(): boolean |
MessageParcel | writeFileDescriptor(fd: number): boolean | MessageSequence | writeFileDescriptor(fd: number): void |
MessageParcel | readFileDescriptor(): number | MessageSequence | readFileDescriptor(): number |
MessageParcel | writeAshmem(ashmem: Ashmem): boolean | MessageSequence | writeAshmem(ashmem: Ashmem): void |
MessageParcel | readAshmem(): Ashmem | MessageSequence | readAshmem(): Ashmem |
MessageParcel | writeRawData(rawData: number[], size: number): boolean | MessageSequence | writeRawData(rawData: number[], size: number): void |
MessageParcel | readRawData(size: number): number[] | MessageSequence | readRawData(size: number): number[] |
Sequenceable | marshalling(dataOut: MessageParcel): boolean | Parcelable | marshalling(dataOut: MessageSequence): boolean |
Sequenceable | unmarshalling(dataIn: MessageParcel) : boolean | Parcelable | unmarshalling(dataIn: MessageSequence) : boolean |
SendRequestResult | errCode: number | RequestResult | errCode: number |
SendRequestResult | code: number | RequestResult | code: number |
SendRequestResult | data: MessageParcel | RequestResult | data: MessageSequence |
SendRequestResult | reply: MessageParcel | RequestResult | reply: MessageSequence |
IRemoteObject | queryLocalInterface(descriptor: string): IRemoteBroker | NA | getLocalInterface(descriptor: string): IRemoteBroker |
IRemoteObject | getInterfaceDescriptor(): string | NA | getDescriptor(): string |
IRemoteObject | addDeathRecipient(recipient: DeathRecipient, flags: number): boolean | NA | registerDeathRecipient(recipient: DeathRecipient, flags: number): void |
IRemoteObject | removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean | NA | unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void |
IRemoteObject | NA | NA | sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise |
IRemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback |
NA | sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption,callback: AsyncCallback |
MessageOption | NA | NA | isAsync(): boolean |
MessageOption | NA | NA | setAsync(async: boolean): void |
MessageOption | NA | NA | constructor(async?: boolean) |
RemoteObject | queryLocalInterface(descriptor: string): IRemoteBroker | NA | getLocalInterface(descriptor: string): IRemoteBroker |
RemoteObject | attachLocalInterface(localInterface: IRemoteBroker, descriptor: string): void | NA | modifyLocalInterface(localInterface: IRemoteBroker, descriptor: string): void |
RemoteObject | getInterfaceDescriptor(): string | NA | getDescriptor(): string |
RemoteObject | onRemoteRequestEx(code : number, data : MessageParcel, reply: MessageParcel, options : MessageOption): boolean | Promise |
NA | onRemoteMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): boolean | Promise |
RemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise |
NA | sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise |
RemoteObject | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback |
NA | sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback |
RemoteProxy | queryLocalInterface(interface: string): IRemoteBroker | NA | getLocalInterface(descriptor: string): IRemoteBroker |
RemoteProxy | getInterfaceDescriptor(): string | NA | getDescriptor(): string |
RemoteProxy | addDeathRecipient(recipient: DeathRecipient, flags: number): boolean | NA | registerDeathRecipient(recipient: DeathRecipient, flags: number): void |
RemoteProxy | removeDeathRecipient(recipient: DeathRecipient, flags: number): boolean | NA | unregisterDeathRecipient(recipient: DeathRecipient, flags: number): void |
RemoteProxy | NA | NA | sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption): Promise |
RemoteProxy | sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback |
NA | sendMessageRequest(code: number, data: MessageSequence, reply: MessageSequence, options: MessageOption, callback: AsyncCallback |
IPCSkeleton | static flushCommands(object: IRemoteObject): number | NA | static flushCmdBuffer(object: IRemoteObject): void |
IPCSkeleton | static setCallingIdentity(identity: string): boolean | NA | static restoreCallingIdentity(identity: string): void |
Ashmem | static createAshmem(name: string, size: number): Ashmem | NA | static create(name: string, size: number): Ashmem |
Ashmem | static createAshmemFromExisting(ashmem: Ashmem): Ashmem | NA | static create(ashmem: Ashmem): Ashmem |
Ashmem | mapAshmem(mapType: number): boolean | NA | mapTypedAshmem(mapType: number): void |
Ashmem | mapReadAndWriteAshmem(): boolean | NA | mapReadWriteAshmem(): void |
Ashmem | mapReadOnlyAshmem(): boolean | NA | mapReadonlyAshmem(): void |
Ashmem | setProtection(protectionType: number): boolean | NA | setProtectionType(protectionType: number): void |
Ashmem | writeToAshmem(buf: number[], size: number, offset: number): boolean | NA | writeAshmem(buf: number[], size: number, offset: number): void |
Ashmem | readFromAshmem(size: number, offset: number): number[] | NA | readAshmem(size: number, offset: number): number[] |
Adaptation Guide
The new APIs return error codes and error information by throwing exceptions. The following uses the create() API of MessageParcel as an example.
import rpc from '@ohos.rpc'
try {
var data = rpc.MessageParcel.create();
data.reclaim();
} catch (error) {
console.info("create meassageParcel failed, errorCode = " + error.errCode);
console.info("create meassageParcel failed, errorMessage = " + error.errorMessage);
}
For details about the APIs, see RPC.