content: /*
   *  Copyright (C) 2017-present Albie Liang. All rights reserved.
   *
   *  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.
   *
   */
  
  package cc.suitalk.ipcinvoker.sample.async;
  
  import android.os.Parcel;
  
  import cc.suitalk.ipcinvoker.IPCAsyncInvokeTask;
  import cc.suitalk.ipcinvoker.IPCInvokeCallback;
  import cc.suitalk.ipcinvoker.IPCInvoker;
  import cc.suitalk.ipcinvoker.extension.XParcelable;
  import cc.suitalk.ipcinvoker.sample.IPCSampleData;
  import cc.suitalk.ipcinvoker.sample.service.MainProcessIPCService;
  import cc.suitalk.ipcinvoker.tools.Log;
  
  /**
   * Created by albieliang on 2017/5/30.
   */
  
  public class IPCInvokeSample_InvokeByTypeWithData {
  
      private static final String TAG = "IPCInvokerSample.IPCInvokeSample_InvokeByTypeWithData";
  
      public static void invokeAsync() {
          IPCRemoteInvoke_PrintWithData o = new IPCRemoteInvoke_PrintWithData();
          o.name = "AlbieLiang";
          o.pid = android.os.Process.myPid();
          IPCInvoker.invokeAsync(MainProcessIPCService.PROCESS_NAME, o, IPCRemoteInvoke_PrintWithData.class, new IPCInvokeCallback<IPCSampleData>() {
              @Override
              public void onCallback(IPCSampleData data) {
                  Log.i(TAG, "onCallback : %s", data.result);
              }
          });
      }
  
  
      private static class IPCRemoteInvoke_PrintWithData implements IPCAsyncInvokeTask<IPCRemoteInvoke_PrintWithData, IPCSampleData>, XParcelable {
  
          private String name;
          private int pid;
  
          @Override
          public void invoke(IPCRemoteInvoke_PrintWithData data, IPCInvokeCallback<IPCSampleData> callback) {
              IPCSampleData result = new IPCSampleData();
              result.result = String.format("name:%s|fromPid:%s|curPid:%s", data.name, data.pid, android.os.Process.myPid());
              callback.onCallback(result);
          }
  
          @Override
          public void writeToParcel(Parcel dest) {
              dest.writeString(name);
              dest.writeInt(pid);
          }
  
          @Override
          public void readFromParcel(Parcel in) {
              this.name = in.readString();
              this.pid = in.readInt();
          }
      }
  }
  