Home | History | Annotate | Download | only in libcamera2
      1 /*
      2 **
      3 ** Copyright 2008, The Android Open Source Project
      4 ** Copyright 2012, Samsung Electronics Co. LTD
      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 
     19 /*!
     20  * \file      SignalDrivenThread.h
     21  * \brief     header file for general thread ( for camera hal2 implementation )
     22  * \author    Sungjoong Kang(sj3.kang (at) samsung.com)
     23  * \date      2012/05/31
     24  *
     25  * <b>Revision History: </b>
     26  * - 2012/05/31 : Sungjoong Kang(sj3.kang (at) samsung.com) \n
     27  *   Initial Release
     28  *
     29  * - 2012/07/10 : Sungjoong Kang(sj3.kang (at) samsung.com) \n
     30  *   2nd Release
     31  *
     32  */
     33 
     34 
     35 
     36 #ifndef SIGNAL_DRIVEN_THREAD_H
     37 #define SIGNAL_DRIVEN_THREAD_H
     38 
     39 #include <utils/threads.h>
     40 
     41 namespace android {
     42 
     43 #define SIGNAL_THREAD_TERMINATE     (1<<0)
     44 #define SIGNAL_THREAD_PAUSE         (1<<1)
     45 
     46 #define SIGNAL_THREAD_COMMON_LAST   (1<<3)
     47 
     48 class SignalDrivenThread:public Thread {
     49 public:
     50                         SignalDrivenThread();
     51                         SignalDrivenThread(const char *name,
     52                             int32_t priority, size_t stack);
     53     virtual             ~SignalDrivenThread();
     54 
     55             status_t    SetSignal(uint32_t signal);
     56 
     57             uint32_t    GetProcessingSignal();
     58             //void        ClearProcessingSignal(uint32_t signal);
     59             void        Start(const char *name,
     60                             int32_t priority, size_t stack);
     61             bool        IsTerminated();
     62 
     63 private:
     64             status_t    readyToRun();
     65             status_t    readyToRunInternal();
     66 
     67             bool        threadLoop();
     68     virtual void        threadFunctionInternal() = 0;
     69 
     70             void        ClearSignal();
     71 
     72             uint32_t    m_receivedSignal;
     73             uint32_t    m_processingSignal;
     74             uint32_t    m_pendingSignal;
     75 
     76             Mutex       m_signalMutex;
     77             Condition   m_threadCondition;
     78             bool	    m_isTerminated;
     79 };
     80 
     81 }; // namespace android
     82 
     83 #endif
     84