• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __DIAG_THREAD_H__
18 #define __DIAG_THREAD_H__
19 
20 #include <utils/List.h>
21 #include <utils/threads.h>
22 
23 namespace android {
24 
25 class CommonClock;
26 class LocalClock;
27 
28 class DiagThread : public Thread {
29   public:
30     DiagThread(CommonClock* common_clock, LocalClock* local_clock);
31     ~DiagThread();
32 
33     status_t      startWorkThread();
34     void          stopWorkThread();
35     virtual bool  threadLoop();
36 
37     void pushDisciplineEvent(int64_t observed_local_time,
38                              int64_t observed_common_time,
39                              int64_t nominal_common_time,
40                              int32_t total_correction,
41                              int32_t rtt);
42 
43   private:
44     typedef struct {
45         int64_t event_id;
46         int64_t action_local_time;
47         int64_t action_common_time;
48         int64_t observed_local_time;
49         int64_t observed_common_time;
50         int64_t nominal_common_time;
51         int32_t total_correction;
52         int32_t rtt;
53     } DisciplineEventRecord;
54 
55     bool            openListenSocket();
56     void            cleanupListenSocket();
57     void            cleanupDataSocket();
58     void            resetLogIDs();
59 
60     CommonClock*    common_clock_;
61     LocalClock*     local_clock_;
62     int             listen_fd_;
63     int             data_fd_;
64 
65     int64_t         kernel_logID_basis_;
66     bool            kernel_logID_basis_known_;
67 
68     static const size_t         kMaxDisciplineLogSize = 16;
69     Mutex                       discipline_log_lock_;
70     List<DisciplineEventRecord> discipline_log_;
71     int64_t                     discipline_log_ID_;
72 };
73 
74 }  // namespace android
75 
76 #endif  //__ DIAG_THREAD_H__
77