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
00008 #include "FCam/Frame.h"
00009 #include "FCam/N900/Sensor.h"
00010 #include "FCam/TSQueue.h"
00011 #include "FCam/N900/Frame.h"
00012
00013 #include "V4L2Sensor.h"
00014
00015
00016
00017 namespace FCam {
00018 namespace N900 {
00019
00020
00021
00022 class Daemon {
00023 public:
00024
00025 class Action {
00026 public:
00027
00028
00029
00030 Time time;
00031 FCam::Action *action;
00032
00033 bool operator<(const Action &other) const {
00034
00035 return time > other.time;
00036 }
00037
00038 bool operator>(const Action &other) const {
00039
00040 return time < other.time;
00041 }
00042 };
00043
00044
00045 Daemon(Sensor *sensor);
00046 ~Daemon();
00047
00048
00049 void setDropPolicy(Sensor::DropPolicy p, int f);
00050
00051
00052
00053 TSQueue<_Frame *> requestQueue;
00054
00055
00056
00057 TSQueue<_Frame *> frameQueue;
00058
00059 void launchThreads();
00060
00061 private:
00062
00063
00064 V4L2Sensor *v4l2Sensor;
00065
00066
00067 Sensor *sensor;
00068
00069 bool stop;
00070
00071
00072 size_t frameLimit;
00073
00074 Sensor::DropPolicy dropPolicy;
00075 void enforceDropPolicy();
00076
00077
00078
00079 TSQueue<_Frame *> inFlightQueue;
00080
00081
00082
00083
00084 pthread_mutex_t cameraMutex;
00085
00086
00087 bool pipelineFlush;
00088
00089
00090
00091 std::priority_queue<Action> actionQueue;
00092 pthread_mutex_t actionQueueMutex;
00093 sem_t actionQueueSemaphore;
00094
00095
00096 void runSetter();
00097 pthread_t setterThread;
00098 void tickSetter(Time hs_vs);
00099 bool setterRunning;
00100
00101 _Frame current;
00102 Shot lastGoodShot;
00103
00104
00105 void runHandler();
00106 pthread_t handlerThread;
00107 bool handlerRunning;
00108
00109
00110 void runAction();
00111 pthread_t actionThread;
00112 bool actionRunning;
00113
00114 int daemon_fd;
00115
00116
00117 bool threadsLaunched;
00118
00119 friend void *daemon_setter_thread_(void *arg);
00120 friend void *daemon_handler_thread_(void *arg);
00121 friend void *daemon_action_thread_(void *arg);
00122 };
00123
00124 }
00125 }
00126
00127 #endif