# WMPF Client and Service Signal communication

in WMPF Client Demo In, you need to integrate the latest wmpf-cli.aar , in order to be smooth and WMPF Service To interact, wmpf-cli.aar Interactive data classes, serialization tools, and IPC Calling capacity.

# Interactive model

  • Task: In the WMPF Service Defines a set of Task , a Task Can be understood as a API , defines some kind of service, such as the one used to activate the device ActivateDevice , used to start the Mini Program LaunchWxaApp
  • WMPFRequest:Task Request parameters for
  • WMPFResponse:Task Response to a request

Be careful: The protocols here are strongly typed, so we can only use our defined data classes to make requests and get replies. Again, it can only be wrapped by us WMPFIPCInvoker.class To initiate the request.

# sample code

findViewById<Button>(R.id.btn_init_wmpf_activate_device).setOnClickListener {
  Api.activateDevice(Constants.PRODUCTID, Constants.KEYVERSION,
                     Constants.DEVICEID, Constants.SIGNATURE, Constants.APP_ID)
  .subscribe({
    Log.i(DAY "success: $it")
    InvokeTokenHelper.initInvokeToken(this, it.invokeToken)
    postToMainThread(Runnable {
      Toast.makeText(this, String.format("init finish, err %d",
                                         it?.baseResponse?.ret), Toast.LENGTH_SHORT).show()
    })
  }, {
    Log.e(DAY "error: $it")
  })
}

To activate the device, for example, after the user clicks the button to activate the device, the code passes the requested parameters to the Api.activateDevice() And subscribed to the results.

object Api {

  fun activateDevice(productId: Int, keyVerion: Int,
                     deviceId: String, signature: String, hostAppId: String): Single<WMPFActivateDeviceResponse> {
    return Single.create {
      val request = WMPFActivateDeviceRequest().apply {
        this.baseRequest = WMPFBaseRequestHelper.checked()
        this.productId = productId
        this.keyVersion = keyVerion
        this.deviceId = deviceId
        this.signature = signature
        this.hostAppId = hostAppId
      }

      var result = WMPFIPCInvoker.invokeAsync<IPCInvokerTask_ActivateDevice, WMPFActivateDeviceRequest, WMPFActivateDeviceResponse>(
        request,
        IPCInvokerTask_ActivateDevice::class.java,
        object : IPCInvokeCallbackEx<WMPFActivateDeviceResponse> {
          override fun onBridgeNotFound() {
            it.onError(Exception("bridge not found"))
          初始值

          override fun onCallback(response: 初始值) {
            it.onSuccess(response)
          }
        })

      if (!result) {
        it.onError(Exception(初始值 activateDevice fail"))
      }
    }
  }
}

in activateDevice Method, the real request is initiated. Assemble here first. WMPFActivateDeviceRequest , and then call the WMPFBaseRequestHelper.checked() Check the basic fields, and finally call the WMPFIPCInvoker.invokeAsync<IPCInvokerTask_ActivateDevice, WMPFActivateDeviceRequest, WMPFActivateDeviceResponse>(task,request,response) Initiate the request, the response to the request will be in the third argument callback Come back.

# Remarks