Android Open Source - Android-NetPowerctrl-Shared Device Connection A P I






From Project

Back to project page Android-NetPowerctrl-Shared.

License

The source code is released under:

Copyright (c) 2014, David Gr?ff All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...

If you think the Android project Android-NetPowerctrl-Shared listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package oly.netpowerctrl.device_base.device;
/*www.j av  a 2 s.com*/
import android.support.annotation.NonNull;
import android.util.JsonReader;
import android.util.JsonToken;
import android.util.JsonWriter;

import java.io.IOException;

/**
 * This is used by extensions and their device connections.
 */
public class DeviceConnectionAPI extends DeviceConnection {
    public static final String ID = "API";
    private boolean includeUseCounter = false;

    public DeviceConnectionAPI(Device device) {
        super(device);
        mIsAssignedByDevice = true;
    }

    @SuppressWarnings("unused")
    public void setIncludeUseCounter(boolean includeUseCounter) {
        this.includeUseCounter = includeUseCounter;
    }

    public void toJSON(JsonWriter writer) throws IOException {
        writer.beginObject();
        writer.name("connection_type").value(ID);
        writer.name("HostName").value(mHostName);
        if (includeUseCounter) {
            writer.name("receivedPackets").value(receivedPackets);
            if (not_reachable_reason != null)
                writer.name("not_reachable_reason").value(not_reachable_reason);
        }
        writer.endObject();
    }

    @Override
    public boolean fromJSON(@NonNull JsonReader reader, boolean beginObjectAlreadyCalled) throws IOException, ClassNotFoundException {
        if (!beginObjectAlreadyCalled)
            reader.beginObject();

        while (reader.hasNext()) {
            String name = reader.nextName();
            assert name != null;
            switch (name) {
                case "not_reachable_reason":
                    if (reader.peek() == JsonToken.STRING)
                        not_reachable_reason = reader.nextString();
                    else
                        reader.skipValue();
                    break;
                case "receivedPackets":
                    receivedPackets = reader.nextInt();
                    break;
                case "HostName":
                    mHostName = reader.nextString();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }

        reader.endObject();

        if (mHostName == null)
            mHostName = "";

        return mHostName.length() > 0;
    }

    @Override
    public boolean needResolveName() {
        return false;
    }

    @Override
    public int getDestinationPort() {
        return -1;
    }

    @Override
    public String getProtocol() {
        return ID;
    }

    @Override
    public boolean equalsByDestinationAddress(DeviceConnection otherConnection, boolean lookupDNSName) {
        return mHostName.equals(otherConnection.mHostName);
    }

    @Override
    public int computeHash() {
        StringBuilder builder = new StringBuilder();
        builder.append(ID);
        builder.append(mHostName);
        return builder.toString().hashCode();
    }
}




Java Source Code List

oly.netpowerctrl.device_base.ApplicationTest.java
oly.netpowerctrl.device_base.data.JSONHelper.java
oly.netpowerctrl.device_base.data.StorableInterface.java
oly.netpowerctrl.device_base.device.DeviceConnectionAPI.java
oly.netpowerctrl.device_base.device.DeviceConnectionFabric.java
oly.netpowerctrl.device_base.device.DeviceConnectionHTTP.java
oly.netpowerctrl.device_base.device.DeviceConnectionUDP.java
oly.netpowerctrl.device_base.device.DeviceConnection.java
oly.netpowerctrl.device_base.device.DeviceFeatureFabric.java
oly.netpowerctrl.device_base.device.DeviceFeatureInterface.java
oly.netpowerctrl.device_base.device.DeviceFeatureTemperature.java
oly.netpowerctrl.device_base.device.DevicePort.java
oly.netpowerctrl.device_base.device.Device.java
oly.netpowerctrl.device_base.executables.ExecutableReachability.java
oly.netpowerctrl.device_base.executables.ExecutableType.java
oly.netpowerctrl.device_base.executables.Executable.java
oly.netpowerctrl.plugin.App2PluginCommunication.java
oly.netpowerctrl.plugin.App2PluginService.java
oly.netpowerctrl.plugin.DeviceConnectionStateInterface.java
oly.netpowerctrl.plugin.onDeviceStateChange.java
oly.netpowerctrl.plugin.onServiceStateChange.java