aboutsummaryrefslogtreecommitdiff
path: root/android/WALT/app/src/main/jni/sync_clock_jni.c
blob: 22753fe57dd219d45d9290b0f5d58c29895a3209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sync_clock.h"

#include <android/log.h>
#include <jni.h>


#define APPNAME "ClockSyncJNI"

// This is global so that we don't have to pass it aroundbetween Java and here.
// TODO: come up with some more elegant solution.
struct clock_connection clk;

jlong
Java_org_chromium_latency_walt_WaltUsbConnection_syncClock__III(
    __attribute__((unused)) JNIEnv* env,
    __attribute__((unused)) jobject thiz,
    jint fd,
    jint endpoint_out,
    jint endpoint_in
){
    clk.fd = (int)fd;
    clk.endpoint_in = (int)endpoint_in;
    clk.endpoint_out = (int)endpoint_out;
    clk.t_base = 0;
    sync_clocks(&clk);
    // __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Returned from sync_clocks\n");

    int64_t t_base = clk.t_base;
    return (jlong) t_base;
}

void
Java_org_chromium_latency_walt_WaltUsbConnection_updateBounds() {
    update_bounds(&clk);
}

jint
Java_org_chromium_latency_walt_WaltUsbConnection_getMinE() {
    return clk.minE;
}


jint
Java_org_chromium_latency_walt_WaltUsbConnection_getMaxE() {
    return clk.maxE;
}