#pragma once #include #include "imgproc.h" #include "mutex" #include "itransmit.h" #include "inotify.h" #include "ireceive.h" #include "BlockingQueue.h" #include class UsbImageProcQueue { void(*img_keeper_)(MemoryPtr, bool, void*); void* kp_param_; public: UsbImageProcQueue(NotifyPtr notify) : img_keeper_(nullptr), kp_param_(nullptr) { this->notify = notify; } void push(MemoryPtr image,bool containsimg) { if(img_keeper_) img_keeper_(image, containsimg, kp_param_); else { std::lock_guard lck(mx); HGIntInfo info; if(containsimg) { images.push(image); //images.Put(image); info.From = IMG; info.Code = image->size(); } else { info = *((HGIntInfo*)image->data()); } if(notify) notify->notify(&info, sizeof(info)); } } void set_image_keeper(void(*img_keeper)(MemoryPtr, bool, void*), void* param) { img_keeper_ = img_keeper; kp_param_ = param; } MemoryPtr front() { std::lock_guard lck(mx); auto front = images.front(); return front; //return images.Front(); } MemoryPtr pop() { std::lock_guard lck(mx); if(images.size()>0) { auto front = images.front(); images.pop(); //auto front=images.Take(); return front; } return MemoryPtr(); } bool empty() { std::lock_guard lck(mx); return images.empty(); //return images.Size()>0; } int size() { std::lock_guard lck(mx); return images.size(); //return images.Size(); } int front_datasize() { std::lock_guard lck(mx); if(images.size()<1) return 0; auto img=images.front(); return images.empty() ? 0 : images.front()->size(); //return (images.Size()>0) ? 0 : images.Front()->size(); } void clear() { std::lock_guard lck(mx); while(images.size()>0) images.pop(); } private: std::queue images; //BlockingQueue images; NotifyPtr notify; std::mutex mx; };