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

io.agora.rtm.internal.MetadataImpl Maven / Gradle / Ivy

package io.agora.rtm.internal;

import io.agora.common.internal.CalledByNative;
import io.agora.rtm.Metadata;
import io.agora.rtm.MetadataItem;

class MetadataImpl extends Metadata {
  private static final String TAG = MetadataImpl.class.getSimpleName();

  private long mNativeMetadata = 0;

  @CalledByNative
  public MetadataImpl(long nativeHandle) {
    mNativeMetadata = nativeHandle;
  }

  @Override
  public synchronized void setMajorRevision(long revision) {
    if (mNativeMetadata == 0) {
      return;
    }
    nativeSetMajorRevision(mNativeMetadata, revision);
  }

  @Override
  public synchronized long getMajorRevision() {
    if (mNativeMetadata == 0) {
      return 0;
    }
    return nativeGetMajorRevision(mNativeMetadata);
  }

  @Override
  public synchronized void setMetadataItem(MetadataItem item) {
    if (mNativeMetadata == 0) {
      return;
    }
    if (item == null || item.getKey() == null || item.getValue() == null) {
      throw new IllegalArgumentException("invalid metadata item");
    }
    nativeSetMetadataItem(mNativeMetadata, item);
  }

  @Override
  public synchronized MetadataItem[] getMetadataItems() {
    if (mNativeMetadata == 0) {
      return null;
    }
    return nativeGetMetadataItems(mNativeMetadata);
  }

  @Override
  public synchronized void clearMetadata() {
    if (mNativeMetadata == 0) {
      return;
    }
    nativeClearMetadata(mNativeMetadata);
  }

  public long getNativeMetadata() {
    return mNativeMetadata;
  }

  private native void nativeSetMajorRevision(long nativeMetadataAndroid, long revision);

  private native long nativeGetMajorRevision(long nativeMetadataAndroid);

  private native void nativeSetMetadataItem(long nativeMetadataAndroid, MetadataItem item);

  private native MetadataItem[] nativeGetMetadataItems(long nativeMetadataAndroid);

  private native void nativeClearMetadata(long nativeMetadataAndroid);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy