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 ANDROID_FILTERFW_CORE_NATIVE_PROGRAM_H 18 #define ANDROID_FILTERFW_CORE_NATIVE_PROGRAM_H 19 20 #include <vector> 21 #include <string> 22 23 #include "base/utilities.h" 24 25 namespace android { 26 namespace filterfw { 27 28 class NativeFrame; 29 30 typedef void (*InitFunctionPtr)(void**); 31 typedef void (*SetValueFunctionPtr)(const char*, const char*, void*); 32 typedef void (*GetValueFunctionPtr)(const char*, char*, int, void*); 33 typedef int (*ProcessFunctionPtr)(const char**, const int*, int, char*, int, void*); 34 typedef void (*ResetFunctionPtr)(void*); 35 typedef void (*TeardownFunctionPtr)(void*); 36 37 class NativeProgram { 38 public: 39 // Create an empty native frame. 40 NativeProgram(); 41 42 ~NativeProgram(); 43 44 bool OpenLibrary(const std::string& lib_name); 45 46 bool BindInitFunction(const std::string& func_name); 47 bool BindSetValueFunction(const std::string& func_name); 48 bool BindGetValueFunction(const std::string& func_name); 49 bool BindProcessFunction(const std::string& func_name); 50 bool BindResetFunction(const std::string& func_name); 51 bool BindTeardownFunction(const std::string& func_name); 52 53 bool CallInit(); 54 bool CallSetValue(const std::string& key, const std::string& value); 55 std::string CallGetValue(const std::string& key); 56 bool CallProcess(const std::vector<const char*>& inputs, 57 const std::vector<int>& input_sizes, 58 char* output, 59 int output_size); 60 bool CallReset(); 61 bool CallTeardown(); 62 63 private: 64 // Pointer to the data. Owned by the frame. 65 void* lib_handle_; 66 67 // The function pointers to the native function implementations. 68 InitFunctionPtr init_function_; 69 SetValueFunctionPtr setvalue_function_; 70 GetValueFunctionPtr getvalue_function_; 71 ProcessFunctionPtr process_function_; 72 ResetFunctionPtr reset_function_; 73 TeardownFunctionPtr teardown_function_; 74 75 // Pointer to user data 76 void* user_data_; 77 78 DISALLOW_COPY_AND_ASSIGN(NativeProgram); 79 }; 80 81 } // namespace filterfw 82 } // namespace android 83 84 #endif // ANDROID_FILTERFW_CORE_NATIVE_PROGRAM_H 85