1 /* 2 * Copyright 2023 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 #include <base/callback.h> 18 #include <base/functional/bind.h> 19 #include <base/location.h> 20 21 #include <string> 22 23 #include "common/contextual_callback.h" 24 #include "module.h" 25 #include "module_jniloop.h" 26 #include "module_mainloop.h" 27 28 using namespace bluetooth; 29 30 void external_function(int /* a */, double /* b */, char /* c */); 31 32 class TestGdxModule : public Module, public ModuleMainloop, public ModuleJniloop { 33 public: 34 void call_on_handler_protected_method(pid_t tid, int a, int b, int c); 35 void call_on_main_external_function(pid_t tid, int a, double b, char c); 36 void call_on_main(pid_t tid, int a, int b, int c); 37 void call_on_main_repost(pid_t tid, int a, int b, int c); 38 void call_on_main_recurse(pid_t tid, int a, int b, int c); 39 40 void call_on_jni_external_function(pid_t tid, int a, double b, char c); 41 void call_on_jni(pid_t tid, int a, int b, int c); 42 void call_on_jni_repost(pid_t tid, int a, int b, int c); 43 void call_on_jni_recurse(pid_t tid, int a, int b, int c); 44 45 void set_callback(common::ContextualCallback<void(std::string)> one_message_callback); 46 void set_once_callback(common::ContextualOnceCallback<void(std::string)> one_message_callback); 47 48 void call_callback_on_handler(std::string message); 49 void call_once_callback_on_handler(std::string message); 50 void call_callback_on_jni(std::string message); 51 void call_once_callback_on_jni(std::string message); 52 void call_callback_on_main(std::string message); 53 void call_once_callback_on_main(std::string message); 54 55 static const bluetooth::ModuleFactory Factory; 56 57 protected: 58 void protected_method(int a, int b, int c); 59 void call_on_main_internal(int a, int b, int c); 60 void call_on_jni_internal(int a, int b, int c); 61 bool IsStarted() const; 62 ListDependencies(bluetooth::ModuleList *)63 void ListDependencies(bluetooth::ModuleList* /* list */) const override {} 64 void Start() override; 65 void Stop() override; 66 std::string ToString() const override; 67 68 private: 69 struct PrivateImpl; 70 std::shared_ptr<TestGdxModule::PrivateImpl> pimpl_; 71 72 common::ContextualOnceCallback<void(std::string)> call_once_; 73 common::ContextualCallback<void(std::string)> call_many_; 74 75 bool started_ = false; 76 77 friend bluetooth::ModuleRegistry; 78 }; 79