Home | History | Annotate | Download | only in tuningfork
      1 /*
      2  * Copyright 2018 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 #pragma once
     18 
     19 #include <thread>
     20 #include <mutex>
     21 #include <map>
     22 #include <condition_variable>
     23 #include "prong.h"
     24 
     25 namespace tuningfork {
     26 
     27 class UploadThread {
     28 private:
     29     std::unique_ptr<std::thread> thread_;
     30     std::mutex mutex_;
     31     std::condition_variable cv_;
     32     bool do_quit_;
     33     const ProngCache *ready_;
     34     Backend *backend_;
     35     ProtobufSerialization current_fidelity_params_;
     36     ProtoCallback upload_callback_;
     37     ExtraUploadInfo extra_info_;
     38  public:
     39     UploadThread(Backend *backend, const ExtraUploadInfo& extraInfo);
     40 
     41     ~UploadThread();
     42 
     43     void Start();
     44 
     45     void Stop();
     46 
     47     void Run();
     48 
     49     // Returns true if we submitted, false if we are waiting for a previous submit to complete
     50     bool Submit(const ProngCache *prongs);
     51 
     52     void SetCurrentFidelityParams(const ProtobufSerialization &fp) {
     53         current_fidelity_params_ = fp;
     54     }
     55 
     56     void SetUploadCallback(ProtoCallback upload_callback) {
     57         upload_callback_ = upload_callback;
     58     }
     59 
     60     static ExtraUploadInfo GetExtraUploadInfo(JNIEnv* env, jobject activity);
     61 
     62  private:
     63     void UpdateGLVersion();
     64 
     65     friend class ClearcutSerializer;
     66 };
     67 
     68 } // namespace tuningfork {
     69