Skip to content

Commit

Permalink
Merge pull request #3 from smartdevicelink/feature/finish_base_rpc
Browse files Browse the repository at this point in the history
Feature/finish base rpc
  • Loading branch information
Nick Schwab authored Aug 6, 2019
2 parents ec9611d + 53cd2b9 commit 1053a46
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 16 deletions.
10 changes: 0 additions & 10 deletions lib/js/rpc/RpcMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ class RpcMessage extends RpcStruct {
return this;
}

getCorrelationID() {
return this._correlationID;
}

setCorrelationID(id) {
this._correlationID = id;

return this;
}

getBulkData() {
return this._bulkData;
}
Expand Down
34 changes: 33 additions & 1 deletion lib/js/rpc/RpcRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,39 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

class RpcRequest {

import { RpcMessage } from './RpcMessage.js';
import { RpcType } from './enums/RpcType.js';

class RpcRequest extends RpcMessage {


constructor(store) {
super(store);
this.setRPCType(RpcType.REQUEST);
this._promise = null;
}

getCorrelationID() {
return this._correlationID;
}

setCorrelationID(id) {
this._correlationID = id;

return this;
}

getOnRPCResponsePromise(){
return this._promise;
}

setOnRPCResponsePromise(promise){
this.validateType(Promise, promise);

this._promise = promise;
return this;
}

}

Expand Down
52 changes: 51 additions & 1 deletion lib/js/rpc/RpcResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,58 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

class RpcResponse {
import { RpcMessage } from './RpcMessage.js';
import { RpcType } from './enums/RpcType.js';
import { Result } from './enums/Result.js';

class RpcResponse extends RpcMessage {


static KEY_SUCCESS = 'success';
static KEY_INFO = 'info';
static KEY_RESULT_CODE = 'resultCode';


constructor(store) {
super(store);
this.setRPCType(RpcType.RESPONSE);
}

getCorrelationID() {
return this._correlationID;
}

setCorrelationID(id) {
this._correlationID = id;

return this;
}

getSuccess(){
return this.getParameter(KEY_SUCCESS);
}

setSuccess(success){
return this.setParameter(KEY_SUCCESS, success);
}

getInfo(){
return this.getParameter(KEY_INFO);
}

setInfo(info){
return this.setParameter(KEY_INFO, info);
}

getResultCode(){
return this.getObject(Result, KEY_RESULT_CODE);
}

setResultCode(resultCode){
this.validateType(Result, resultCode);

return this.setParameter(KEY_RESULT_CODE, resultCode);
}
}

export { RpcResponse };
5 changes: 4 additions & 1 deletion lib/js/rpc/RpcStruct.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class RpcStruct {
}

validateType(tClass, obj) {
if (obj !== null && obj.constructor !== tClass) {
if (
(tClass instanceof Enum && tClass.valueForString(obj) === null)
|| (obj !== null && obj.constructor !== tClass)
) {
throw `${obj.name} must be of type ${tClass.name}`;
}
}
Expand Down
66 changes: 66 additions & 0 deletions lib/js/rpc/enums/FunctionIDType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

/*
* Copyright (c) 2019, Livio, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* Neither the name of the Livio Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

import { Enum } from '../../util/Enum.js';

class FunctionID extends Enum {
static MAP = Object.freeze({
'AddCommand': 0x05,
'OnLanguageChange': 0x800A,
//TODO this needs to be completely filled out still
});

constructor() {
super();
}

static get ADD_COMMAND(){
return FunctionID.MAP.AddCommand;
}

static get ON_LANGUAGE_CHANGE(){
return FunctionID.MAP.OnLanguageChange;
}


static valueForString(value) {
return FunctionID.valueForStringInternal(value, FunctionID.MAP);
}

static keyForValue(value) {
return FunctionID.keyForValueInternal(value, FunctionID.MAP);
}
}


export { FunctionID }
Loading

0 comments on commit 1053a46

Please sign in to comment.