/**
   * Sends a blocking FCP message to the WoT plugin, checks whether the reply is really the expected
   * reply message and throws an exception if not. Also checks whether the reply is an error message
   * and throws an exception if it is. Therefore, the purpose of this function is that the callee
   * can assume that no errors occurred if no exception is thrown.
   *
   * @param params The params of the FCP message.
   * @param expectedReplyMessage The excepted content of the "Message" field of the SimpleFieldSet
   *     of the reply message.
   * @return The unmodified HashResult object which was returned by the PluginTalker.
   * @throws WoTDisconnectedException If the connection to WoT was lost.
   * @throws Exception If the WoT plugin replied with an error message or not with the expected
   *     message.
   */
  private PluginTalkerBlocking.Result sendFCPMessageBlocking(
      SimpleFieldSet params, Bucket data, String expectedReplyMessage) throws Exception {
    if (mTalker == null) throw new WoTDisconnectedException();

    PluginTalkerBlocking.Result result;
    try {
      result = mTalker.sendBlocking(params, data);
    } catch (PluginNotFoundException e) {
      throw new WoTDisconnectedException();
    }

    if (result.params.get("Message").equals("Error")) {
      final String description = result.params.get("Description");

      if (description.indexOf("UnknownIdentityException") >= 0)
        throw new NoSuchIdentityException(description);

      throw new Exception(
          "FCP message " + result.params.get("OriginalMessage") + " failed: " + description);
    }

    if (result.params.get("Message").equals(expectedReplyMessage) == false)
      throw new Exception(
          "FCP message "
              + params.get("Message")
              + " received unexpected reply: "
              + result.params.get("Message"));

    return result;
  }
  private synchronized boolean connectToWoT() {
    if (mTalker != null) {
        /* Old connection exists */
      SimpleFieldSet sfs = new SimpleFieldSet(true);
      sfs.putOverwrite("Message", "Ping");
      try {
        mTalker.sendBlocking(sfs, null); /* Verify that the old connection is still alive */
        return true;
      } catch (PluginNotFoundException e) {
        mTalker = null;
        /* Do not return, try to reconnect in next try{} block */
      }
    }

    try {
      mTalker = new PluginTalkerBlocking(mFreetalk.getPluginRespirator());
      mFreetalk.handleWotConnected();
      return true;
    } catch (PluginNotFoundException e) {
      mFreetalk.handleWotDisconnected();
      return false;
    }
  }