00001 #ifndef FCAM_N900_DAEMON_H
00002 #define FCAM_N900_DAEMON_H
00003
00004 #include <queue>
00005 #include <pthread.h>
00006 #include <semaphore.h>
00007 #include "../Frame.h"
00008 #include "V4L2Sensor.h"
00009 #include "../Sensor.h"
00010 #include "Frame.h"
00011
00012 namespace FCam {
00013 namespace N900 {
00014
00015
00016
00017 class Daemon {
00018 public:
00019
00020 class Action {
00021 public:
00022
00023
00024
00025 Time time;
00026 FCam::Action *action;
00027
00028 bool operator<(const Action &other) const {
00029
00030 return time > other.time;
00031 }
00032
00033 bool operator>(const Action &other) const {
00034
00035 return time < other.time;
00036 }
00037 };
00038
00039
00040 Daemon();
00041 ~Daemon();
00042
00043 class RequestGenerator {
00044 public:
00045 virtual void generateRequest() = 0;
00046 };
00047
00048 void setRequestGenerator(RequestGenerator *gen);
00049 RequestGenerator *getRequestGenerator();
00050
00051 int requestFrame(Frame *);
00052
00053
00054 void setDropPolicy(Sensor::DropPolicy p, int f);
00055
00056 Frame *getNextFrame();
00057 int framesPending() const {return frameQueue.size();}
00058
00059 private:
00060
00061
00062 V4L2Sensor *sensor;
00063
00064 bool stop;
00065
00066
00067
00068 std::queue<Frame *> requestQueue;
00069 pthread_mutex_t requestQueueMutex;
00070
00071
00072
00073 RequestGenerator *generator;
00074
00075
00076
00077 std::queue<Frame *> frameQueue;
00078 pthread_mutex_t frameQueueMutex;
00079 sem_t frameQueueSemaphore;
00080
00081 size_t frameLimit;
00082
00083 Sensor::DropPolicy dropPolicy;
00084 void enforceDropPolicy();
00085
00086
00087
00088 std::queue<Frame *> inFlightQueue;
00089 pthread_mutex_t inFlightQueueMutex;
00090
00091
00092
00093
00094 pthread_mutex_t cameraMutex;
00095
00096
00097 bool pipelineFlush;
00098
00099
00100
00101 std::priority_queue<Action> actionQueue;
00102 pthread_mutex_t actionQueueMutex;
00103 sem_t actionQueueSemaphore;
00104
00105 void launchThreads();
00106
00107
00108 void runSetter();
00109 pthread_t setterThread;
00110 void tickSetter(Time hs_vs);
00111 bool setterRunning;
00112
00113 Frame current;
00114
00115
00116 void runHandler();
00117 pthread_t handlerThread;
00118 bool handlerRunning;
00119
00120
00121 void runAction();
00122 pthread_t actionThread;
00123 bool actionRunning;
00124
00125 int daemon_fd;
00126
00127 bool waitingForFirstRequest;
00128
00129 friend void *daemon_setter_thread_(void *arg);
00130 friend void *daemon_handler_thread_(void *arg);
00131 friend void *daemon_action_thread_(void *arg);
00132 };
00133
00134 }
00135 }
00136
00137 #endif