ParticleDevice.java 文件源码

java
阅读 33 收藏 0 点赞 0 评论 0

项目:xlight_android_native 作者:
/**
 * Call a function on the device
 *
 * @param functionName Function name
 * @param args         Array of arguments to pass to the function on the device.
 *                     Arguments must not be more than MAX_PARTICLE_FUNCTION_ARG_LENGTH chars
 *                     in length. If any arguments are longer, a runtime exception will be thrown.
 * @return result code: a value of 1 indicates success
 */
@WorkerThread
public int callFunction(String functionName, @Nullable List<String> args)
        throws ParticleCloudException, IOException, FunctionDoesNotExistException {
    // TODO: check response of calling a non-existent function
    if (!deviceState.functions.contains(functionName)) {
        throw new FunctionDoesNotExistException(functionName);
    }

    // null is accepted here, but it won't be in the Retrofit API call later
    if (args == null) {
        args = list();
    }

    String argsString = ParticleInternalStringUtils.join(args, ',');
    Preconditions.checkArgument(argsString.length() < MAX_PARTICLE_FUNCTION_ARG_LENGTH,
            String.format("Arguments '%s' exceed max args length of %d",
                    argsString, MAX_PARTICLE_FUNCTION_ARG_LENGTH));

    Responses.CallFunctionResponse response;
    try {
        response = mainApi.callFunction(deviceState.deviceId, functionName,
                new FunctionArgs(argsString));
    } catch (RetrofitError e) {
        throw new ParticleCloudException(e);
    }

    if (!response.connected) {
        cloud.onDeviceNotConnected(deviceState);
        throw new IOException("Device is not connected.");
    } else {
        return response.returnValue;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号