All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tinymediamanager.jsonrpc.config.HostConfig Maven / Gradle / Ivy

Go to download

This library is the result of freezy's Kodi JSON introspection, merged with dereulenspiegel's adoption without android, and patched to Kodi 16 Jarvis.

The newest version!
/*
 *      Copyright (C) 2005-2015 Team XBMC
 *      http://xbmc.org
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with XBMC Remote; see the file license.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

package org.tinymediamanager.jsonrpc.config;

import java.util.Locale;

/**
 * A set of configuration data needed to connect to an XBMC host.
 * 
 * @author freezy 
 */
public class HostConfig {

  /**
   * IP or host name of XBMC.
   */
  public final String mAddress;
  /**
   * HTTP port where JSON-RPC sits (defaults to 8080 on any platform but Windows, where it's 80).
   */
  public final int    mHttpPort;
  /**
   * TCP port of JSON-RPC (defauls to 9090).
   */
  public final int    mTcpPort;
  /**
   * Username, if authentication enabled.
   */
  public final String mUsername;
  /**
   * Password, if authentication enabled.
   */
  public final String mPassword;

  private static int  DEFAULT_HTTP_PORT = 8080;

  static {
    if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) {
      DEFAULT_HTTP_PORT = 80;
    }
  }

  /**
   * Creates a new XBMC host object.
   * 
   * @param address
   *          IP or host adress of XBMC
   */
  public HostConfig(String address) {
    this(address, DEFAULT_HTTP_PORT);
  }

  /**
   * Creates a new XBMC host object.
   * 
   * @param address
   *          IP or host adress of XBMC
   * @param httpPort
   *          HTTP port where JSON-RPC sits (defaults to 8080 on any platform but Windows, where it's 80).
   */
  public HostConfig(String address, int httpPort) {
    this(address, httpPort, 9090);
  }

  /**
   * Creates a new XBMC host object.
   * 
   * @param address
   *          IP or host adress of XBMC
   * @param httpPort
   *          HTTP port where JSON-RPC sits (defaults to 8080 on any platform but Windows, where it's 80).
   * @param tcpPort
   *          TCP port of JSON-RPC (defauls to 9090).
   */
  public HostConfig(String address, int httpPort, int tcpPort) {
    this(address, httpPort, tcpPort, null, null);
  }

  /**
   * Creates a new XBMC host object.
   * 
   * @param address
   *          IP or host adress of XBMC
   * @param httpPort
   *          HTTP port where JSON-RPC sits (defaults to 8080 on any platform but Windows, where it's 80).
   * @param username
   *          Username, if authentication enabled.
   * @param password
   *          Password, if authentication enabled.
   */
  public HostConfig(String address, int httpPort, String username, String password) {
    this(address, httpPort, 9090, username, password);
  }

  /**
   * Creates a new XBMC host object.
   * 
   * @param address
   *          IP or host adress of XBMC
   * @param httpPort
   *          HTTP port where JSON-RPC sits (defaults to 8080 on any platform but Windows, where it's 80).
   * @param tcpPort
   *          TCP port of JSON-RPC (defauls to 9090).
   * @param username
   *          Username, if authentication enabled.
   * @param password
   *          Password, if authentication enabled.
   */
  public HostConfig(String address, String httpPort, String tcpPort, String username, String password) {
    int h = 0;
    int t = 0;
    try {
      h = Integer.parseInt(httpPort);
      t = Integer.parseInt(tcpPort);
    }
    catch (Exception e) {
      // ignore
    }
    mAddress = address;
    mHttpPort = h == 0 ? DEFAULT_HTTP_PORT : h;
    mTcpPort = t == 0 ? 9090 : t;
    mUsername = username;
    mPassword = password;
  }

  /**
   * Creates a new XBMC host object.
   * 
   * @param address
   *          IP or host adress of XBMC
   * @param httpPort
   *          HTTP port where JSON-RPC sits (defaults to 8080 on any platform but Windows, where it's 80).
   * @param tcpPort
   *          TCP port of JSON-RPC (defauls to 9090).
   * @param username
   *          Username, if authentication enabled.
   * @param password
   *          Password, if authentication enabled.
   */
  public HostConfig(String address, int httpPort, int tcpPort, String username, String password) {
    mAddress = address;
    mHttpPort = httpPort == 0 ? DEFAULT_HTTP_PORT : httpPort;
    mTcpPort = tcpPort == 0 ? 9090 : tcpPort;
    mUsername = username;
    mPassword = password;
  }

  public String getAddress() {
    return mAddress;
  }

  public int getHttpPort() {
    return mHttpPort;
  }

  public int getTcpPort() {
    return mTcpPort;
  }

  public String getUsername() {
    return mUsername;
  }

  public String getPassword() {
    return mPassword;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy