1 /* 2 * worker.h - worker class interface 3 * 4 * Copyright (c) 2017 Intel Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Wind Yuan <feng.yuan@intel.com> 19 */ 20 21 #ifndef XCAM_WORKER_H 22 #define XCAM_WORKER_H 23 24 #include <xcam_std.h> 25 26 #define ENABLE_FUNC_OBJ 0 27 28 #define DECLARE_WORK_CALLBACK(CbClass, Handler, mem_func) \ 29 class CbClass : public ::XCam::Worker::Callback { \ 30 private: ::XCam::SmartPtr<Handler> _h; \ 31 public: CbClass (const ::XCam::SmartPtr<Handler> &h) { _h = h;} \ 32 protected: void work_status ( \ 33 const ::XCam::SmartPtr<::XCam::Worker> &worker, \ 34 const ::XCam::SmartPtr<::XCam::Worker::Arguments> &args, \ 35 const XCamReturn error) { \ 36 _h->mem_func (worker, args, error); } \ 37 } 38 39 namespace XCam { 40 41 class Worker 42 : public RefObj 43 { 44 public: 45 struct Arguments 46 { ArgumentsArguments47 Arguments () {} ~ArgumentsArguments48 virtual ~Arguments () {} 49 50 XCAM_DEAD_COPY (Arguments); 51 }; 52 53 class Callback { 54 public: Callback()55 Callback () {} ~Callback()56 virtual ~Callback () {} 57 58 virtual void work_status ( 59 const SmartPtr<Worker> &worker, const SmartPtr<Arguments> &args, const XCamReturn error) = 0; 60 61 private: 62 XCAM_DEAD_COPY (Callback); 63 }; 64 65 #if ENABLE_FUNC_OBJ 66 class FuncObj { 67 public: ~FuncObj()68 virtual ~FuncObj () {} 69 virtual XCamReturn impl (const SmartPtr<Arguments> &args) = 0; 70 71 private: 72 XCAM_DEAD_COPY (FuncObj); 73 }; 74 #endif 75 76 protected: 77 explicit Worker (const char *name, const SmartPtr<Callback> &cb = NULL); 78 79 public: 80 virtual ~Worker (); 81 bool set_name (const char *name); get_name()82 const char *get_name () const { 83 return _name; 84 } 85 #if ENABLE_FUNC_OBJ 86 bool set_func_obj (const SmartPtr<FuncObj> &obj); 87 #endif 88 bool set_callback (const SmartPtr<Callback> &callback); 89 90 virtual XCamReturn work (const SmartPtr<Arguments> &args) = 0; 91 virtual XCamReturn stop () = 0; 92 93 protected: 94 virtual void status_check (const SmartPtr<Arguments> &args, const XCamReturn error); 95 96 private: 97 XCAM_DEAD_COPY (Worker); 98 99 private: 100 char *_name; 101 SmartPtr<Callback> _callback; 102 #if ENABLE_FUNC_OBJ 103 SmartPtr<FuncObj> _func_obj; 104 #endif 105 }; 106 107 } 108 #endif //XCAM_WORKER_H 109