001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.cscore;
006
007/** A source or sink property. */
008public class VideoProperty {
009  public enum Kind {
010    kNone(0),
011    kBoolean(1),
012    kInteger(2),
013    kString(4),
014    kEnum(8);
015
016    private final int value;
017
018    Kind(int value) {
019      this.value = value;
020    }
021
022    public int getValue() {
023      return value;
024    }
025  }
026
027  /**
028   * Convert from the numerical representation of kind to an enum type.
029   *
030   * @param kind The numerical representation of kind
031   * @return The kind
032   */
033  public static Kind getKindFromInt(int kind) {
034    switch (kind) {
035      case 1:
036        return Kind.kBoolean;
037      case 2:
038        return Kind.kInteger;
039      case 4:
040        return Kind.kString;
041      case 8:
042        return Kind.kEnum;
043      default:
044        return Kind.kNone;
045    }
046  }
047
048  public String getName() {
049    return CameraServerJNI.getPropertyName(m_handle);
050  }
051
052  public Kind getKind() {
053    return m_kind;
054  }
055
056  public boolean isValid() {
057    return m_kind != Kind.kNone;
058  }
059
060  // Kind checkers
061  public boolean isBoolean() {
062    return m_kind == Kind.kBoolean;
063  }
064
065  public boolean isInteger() {
066    return m_kind == Kind.kInteger;
067  }
068
069  public boolean isString() {
070    return m_kind == Kind.kString;
071  }
072
073  public boolean isEnum() {
074    return m_kind == Kind.kEnum;
075  }
076
077  public int get() {
078    return CameraServerJNI.getProperty(m_handle);
079  }
080
081  public void set(int value) {
082    CameraServerJNI.setProperty(m_handle, value);
083  }
084
085  public int getMin() {
086    return CameraServerJNI.getPropertyMin(m_handle);
087  }
088
089  public int getMax() {
090    return CameraServerJNI.getPropertyMax(m_handle);
091  }
092
093  public int getStep() {
094    return CameraServerJNI.getPropertyStep(m_handle);
095  }
096
097  public int getDefault() {
098    return CameraServerJNI.getPropertyDefault(m_handle);
099  }
100
101  // String-specific functions
102  public String getString() {
103    return CameraServerJNI.getStringProperty(m_handle);
104  }
105
106  public void setString(String value) {
107    CameraServerJNI.setStringProperty(m_handle, value);
108  }
109
110  // Enum-specific functions
111  public String[] getChoices() {
112    return CameraServerJNI.getEnumPropertyChoices(m_handle);
113  }
114
115  VideoProperty(int handle) {
116    m_handle = handle;
117    m_kind = getKindFromInt(CameraServerJNI.getPropertyKind(handle));
118  }
119
120  VideoProperty(int handle, Kind kind) {
121    m_handle = handle;
122    m_kind = kind;
123  }
124
125  int m_handle;
126  private Kind m_kind;
127}