项目需求
平台通过http下发json格式的消息
程序收到消息后 根据日期时间戳去对应的目录检索是否符合要求的文件 比如某个时间段
检索到之后 将视频片段拼接成一个完整的视频文件
没有的话 根据时间戳判断是否需要等待或者 返回没有检索到
头文件
#ifndef QMCY_LED_H
#define QMCY_LED_H
#include
#include
#include
#include
#include
cpp文件
#include "QMCY_DUMP.h"
#include
#include
static semaphore sem;
zlog_category_t *g_zlog;
QMCY_APP::QMCY_APP()
{
m_counter = 0;
std::cout<<__func__< QMCY_APP::GetFiles(const std::string dir,std::string time)
{
int hour,minute,second,sn;
int converted;
unsigned int last_item_time = 0;
int check_times = 0;
std::vector result;
std::map table;
unsigned int keyword;
char path[1000];
strcpy(path,dir.c_str());
DIR *dp;
struct dirent *files;
/*structure for storing inode numbers and files in dir
struct dirent
{
ino_t d_ino;
char d_name[NAME_MAX+1]
}
*/
RECHECK:
result.clear();
table.clear();
check_times++;
if((dp=opendir(path))==NULL)
perror("dir\n");
char newp[1000];
struct stat buf;
while((files=readdir(dp))!=NULL)
{
if(!strcmp(files->d_name,".") || !strcmp(files->d_name,".."))
continue;
strcpy(newp,path);
strcat(newp,"/");
strcat(newp,files->d_name);
//printf("%s\n",newp);
//printf("%s\n",files->d_name);
std::string filename = files->d_name;
std::size_t found = filename.find_last_of(".mp4");
if(found == filename.size() -1)
{
//printf("find :%d\n",found);
converted = sscanf(files->d_name, "%02d-%02d-%02d-%d", &hour, &minute, &second,&sn);
if(converted == 4)
{
unsigned int key = hour*3600+minute*60+second;
table.insert(std::pair(key,files->d_name));
}
}
else
{
printf("not a mp4 file\n");
continue;
}
}
converted = sscanf(time.c_str(), "%02d:%02d:%02d", &hour, &minute, &second);
if(converted == 3)
{
keyword = hour*3600+minute*60+second;
std::cout<<"keyword is:"<=keyword-6 && item.first <=keyword+6)
{
std::cout<<"matched :"<"<"< files = GetFiles(inner_msg.date,inner_msg.time);
std::string filecontent;
if(files.size() >0)
{
for(auto &item:files)
{
std::cout<<"matched :"<- get_tasks();
if(size >= MAX_QUEUE_SIZE)
{
//Need to tell server this task can not be exectued!!!!!
std::cout<<"Task full add failed task size "<AddTask([this,inner_msg](){
RealExecUnit(inner_msg);
});
//std::cout<<" DispatchTask AddTask Exit !!!!!!!!!!!"<pop_data(inner_msg);
if(ret )
{
if(MSG_EXIT_LED == inner_msg.msg_id)
{
std::cout<<"Get exit msg :"< lock(m_table_mutex);
jsonxx::json response ;
#if 0
for(auto it=m_led_table.begin(); it!=m_led_table.end();it++)
{
jsonxx::json item;
auto led = it->second;
if(m_run_flag.load() == false || led == nullptr)
{
return;
}
auto result = led ->NVR_GetStatus();
item["bmsid"]= it->first;
item["status"]= result.first;
item["msg"]= result.second;
response.push_back(std::move(item));
}
auto output = response.dump();
if(output.size())
{
std::cout<<"Report content:"<
Http服务用cpphttp
项目中用到 线程池 等待队列 等