Changeset 330 in flair-src for trunk/lib/FlairCore
- Timestamp:
- Sep 25, 2019, 3:29:26 PM (5 years ago)
- Location:
- trunk/lib/FlairCore
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/CMakeLists.txt
r302 r330 9 9 INCLUDE_DIRECTORIES( 10 10 ${LIBXML2_INCLUDE_DIR} 11 ${CMAKE_SYSROOT}/usr/include/opencv112 11 ${CMAKE_SYSROOT}/usr/include/udt 13 12 ${CMAKE_CURRENT_SOURCE_DIR}/src -
trunk/lib/FlairCore/src/ConditionVariable.cpp
r15 r330 31 31 ConditionVariable::~ConditionVariable() { delete pimpl_; } 32 32 33 void ConditionVariable::CondWait(void) { pimpl_->CondWait(); }33 bool ConditionVariable::CondWait(Time timeout) { return pimpl_->CondWait(timeout); } 34 34 35 35 bool ConditionVariable::CondWaitUntil(Time date) { -
trunk/lib/FlairCore/src/ConditionVariable.h
r15 r330 55 55 * Upon successful return, the mutex has been locked and is owned by the 56 56 *calling thread which should unlock it (see Mutex::ReleaseMutex). 57 * 58 * \param timeout timeout 59 * \return true if the condition variable is signaled before the tipeout specified 60 * in parameter elapses or if timeout elapses, false otherwise 57 61 */ 58 void CondWait(void);62 bool CondWait(Time timeout=TIME_INFINITE); 59 63 60 64 /*! -
trunk/lib/FlairCore/src/ConditionVariable_impl.cpp
r133 r330 53 53 } 54 54 55 void ConditionVariable_impl::CondWait(void) {55 bool ConditionVariable_impl::CondWait(Time timeout) { 56 56 int status; 57 if(timeout==TIME_INFINITE) { 57 58 #ifdef __XENO__ 58 status = 59 rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE); 59 status=rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE); 60 60 #else 61 status =pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);61 status=pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex); 62 62 #endif 63 if (status != 0) { 64 char errorMsg[256]; 65 self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 66 } 63 if(status != 0) { 64 char errorMsg[256]; 65 self->Err("error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 66 return false; 67 } 68 return true; 69 } else { 70 return CondWaitUntil(GetTime()+timeout); 71 } 67 72 } 68 73 … … 72 77 status = rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex, date); 73 78 #else 74 struct timespec restrict;75 restrict.tv_sec = date / 1000000000;76 restrict.tv_nsec = date % 1000000000;79 struct timespec abstime; 80 abstime.tv_sec = date / 1000000000; 81 abstime.tv_nsec = date % 1000000000; 77 82 status = pthread_cond_timedwait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, 78 & restrict);83 &abstime); 79 84 #endif 80 if (status == 0) 81 return true; 85 if (status == 0) return true; 82 86 if (status != ETIMEDOUT) { 83 87 char errorMsg[256]; -
trunk/lib/FlairCore/src/IODevice_impl.cpp
r252 r330 225 225 226 226 wake_mutex->GetMutex(); 227 if (thread_to_wake == NULL) { 228 thread_to_wake = (Thread *)thread; 229 } else { 230 status = -1; 227 if(thread==NULL) { 228 thread_to_wake=NULL; 229 } else { 230 if (thread_to_wake == NULL) { 231 thread_to_wake = (Thread *)thread; 232 } else { 233 status = -1; 234 } 231 235 } 232 236 wake_mutex->ReleaseMutex(); -
trunk/lib/FlairCore/src/Picture.cpp
r137 r330 20 20 #include "Layout.h" 21 21 #include "LayoutPosition.h" 22 #include <string.h> 22 23 23 24 using std::string; … … 45 46 if (image != NULL) { 46 47 image->GetMutex(); 47 memcpy(buf, image-> img->imageData, image->GetDataType().GetSize());48 memcpy(buf, image->buffer, image->GetDataType().GetSize()); 48 49 image->ReleaseMutex(); 49 50 } -
trunk/lib/FlairCore/src/Picture.h
r15 r330 15 15 16 16 #include <SendData.h> 17 #include <cxtypes.h>18 17 19 18 namespace flair { -
trunk/lib/FlairCore/src/RangeFinderPlot.cpp
r252 r330 20 20 #include "Matrix.h" 21 21 #include "LayoutPosition.h" 22 #include <cxcore.h>23 22 24 23 using std::string; -
trunk/lib/FlairCore/src/Thread.cpp
r313 r330 82 82 void Thread::Resume(void) { pimpl_->Resume(); } 83 83 84 int Thread::WaitUpdate(const IODevice *device) {85 return pimpl_->WaitUpdate(device );84 bool Thread::WaitUpdate(const IODevice *device,Time timeout) { 85 return pimpl_->WaitUpdate(device,timeout); 86 86 } 87 87 -
trunk/lib/FlairCore/src/Thread.h
r213 r330 140 140 * 141 141 * \param device IODevice to wait update from 142 */ 143 int WaitUpdate(const IODevice *device); 142 * \return true if device was updated, false otherwise (timeout, etc) 143 */ 144 bool WaitUpdate(const IODevice *device,Time timeout=TIME_INFINITE); 144 145 145 146 /*! -
trunk/lib/FlairCore/src/Thread_impl.cpp
r307 r330 276 276 } 277 277 278 int Thread_impl::WaitUpdate(const IODevice *device) {279 int status = 0;278 bool Thread_impl::WaitUpdate(const IODevice *device,Time timeout) { 279 bool status = true; 280 280 281 281 if (IsSuspended() == true) { 282 282 self->Err("thread is already supended\n"); 283 status = -1;283 status = false; 284 284 } else { 285 285 cond->GetMutex(); … … 287 287 if (device->pimpl_->SetToWake(self) == 0) { 288 288 is_suspended = true; 289 cond->CondWait(); 289 status=cond->CondWait(timeout); 290 if(status==false) device->pimpl_->SetToWake(NULL);//condwait timedout 290 291 is_suspended = false; 291 292 } else { 292 self->Err("%s is already waiting an update\n", 293 device->ObjectName().c_str()); 294 status = -1; 293 self->Err("%s is already waiting an update\n", device->ObjectName().c_str()); 294 status = false; 295 295 } 296 296 -
trunk/lib/FlairCore/src/cvimage.cpp
r252 r330 22 22 namespace core { 23 23 24 char* (*cvimage::allocFunction)(ssize_t)=cvimage::DefaultAllocFunction; 25 void (*cvimage::freeFunction)(char*)=cvimage::DefaultFreeFunction; 26 24 27 cvimage::cvimage(const Object *parent, uint16_t width, uint16_t height, 25 28 Type::Format format, string name, bool allocate_data, int n) 26 29 : io_data(parent, name, n), dataType(width, height, format) { 27 30 this->allocate_data = allocate_data; 28 31 //Printf("cvimage %s\n",ObjectName().c_str()); 29 32 if (allocate_data) { 30 33 switch (format) { 31 34 case Type::Format::YUYV: 32 35 case Type::Format::UYVY: 33 img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U,2);36 buffer=allocFunction(width*height*2); 34 37 break; 35 38 case Type::Format::BGR: 36 img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U,3);39 buffer=allocFunction(width*height*3); 37 40 break; 38 41 case Type::Format::Gray: 39 img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U,1);42 buffer=allocFunction(width*height*1); 40 43 break; 41 44 default: 42 Err("format no supported");45 Err("format not supported"); 43 46 break; 44 47 } … … 47 50 Err("number of samples!=1 not possible when not allocating data\n"); 48 51 n = 1; 49 switch (format) {50 case Type::Format::YUYV:51 case Type::Format::UYVY:52 img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 2);53 break;54 case Type::Format::BGR:55 img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);56 break;57 case Type::Format::Gray:58 img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 1);59 break;60 default:61 Err("format no supported");62 break;63 }64 52 } 65 53 66 SetPtrToCircle((void **)& img);54 SetPtrToCircle((void **)&buffer); 67 55 68 56 if (n > 1) … … 72 60 cvimage::~cvimage() { 73 61 // printf("destructeur cvimage\n"); 74 75 cvReleaseImage(&img); 62 if(allocate_data) freeFunction(buffer); 76 63 } 77 64 78 65 void cvimage::RawRead(char *dst) const { Warn("non implementé\n"); } 79 66 67 void cvimage::RegisterAllocFunction(char*(*func)(ssize_t size)) { 68 if(allocFunction==DefaultAllocFunction) allocFunction=func; 69 } 70 71 void cvimage::RegisterFreeFunction(void(*func)(char* buffer)) { 72 if(freeFunction==DefaultFreeFunction) freeFunction=func; 73 } 74 75 char* cvimage::DefaultAllocFunction(ssize_t size){ 76 Printf("default alloc %i\n",size); 77 return (char*)malloc(size); 78 } 79 80 void cvimage::DefaultFreeFunction(char* buffer){ 81 Printf("default free\n"); 82 free(buffer); 83 } 84 80 85 } // end namespace core 81 86 } // end namespace flair -
trunk/lib/FlairCore/src/cvimage.h
r252 r330 14 14 #define CVIMAGE_H 15 15 16 #include <cxcore.h>17 16 #include <io_data.h> 18 17 #include <stdint.h> 18 19 20 namespace flair { 21 namespace sensor { 22 class V4LCamera; 23 } 24 } 25 19 26 20 27 namespace flair { … … 28 35 */ 29 36 class cvimage : public io_data { 30 public: 37 public: 38 friend class flair::sensor::V4LCamera; 31 39 class Type : public DataType { 32 40 public: … … 97 105 ~cvimage(); 98 106 99 /*! 100 * \brief IplImage 101 * 102 * \return IplImage 103 */ 104 IplImage *img; 107 108 char *buffer; 105 109 106 110 Type const &GetDataType() const { return dataType; }; 111 112 static void RegisterAllocFunction(char*(*func)(ssize_t size)); 113 static void RegisterFreeFunction(void(*func)(char* buffer)); 107 114 108 115 private: … … 119 126 bool allocate_data; 120 127 Type dataType; 128 static char* (*allocFunction)(ssize_t); 129 static void (*freeFunction)(char*); 130 static char* DefaultAllocFunction(ssize_t size); 131 static void DefaultFreeFunction(char* buffer); 132 121 133 }; 122 134 -
trunk/lib/FlairCore/src/unexported/ConditionVariable_impl.h
r15 r330 37 37 ConditionVariable_impl(flair::core::ConditionVariable *self); 38 38 ~ConditionVariable_impl(); 39 void CondWait(void);39 bool CondWait(flair::core::Time timeout); 40 40 bool CondWaitUntil(flair::core::Time date); 41 41 void CondSignal(void); -
trunk/lib/FlairCore/src/unexported/Thread_impl.h
r213 r330 47 47 void Resume(void); 48 48 bool IsSuspended(void); 49 int WaitUpdate(const flair::core::IODevice *device);49 bool WaitUpdate(const flair::core::IODevice *device,flair::core::Time timeout); 50 50 bool period_set; 51 51 bool isRunning;
Note:
See TracChangeset
for help on using the changeset viewer.