I'm getting two compile errors:
/home/sater/projects/MotionManager/videoProcess.cpp:11:1: error: a function-definition is not allowed here before ‘{’ token
/home/sater/projects/MotionManager/main.cpp:85:1: error: expected ‘}’ at end of input
I checked to make sure that all parentheses and brackets were matched, but can't find the root of this problem. Could you please take a look at my code to see if I'm misunderstanding something? I'm new to c++ and am coming from mostly web programming and scripting experience but I'm a learn by doing sort of person so please excuse any mistakes due to not having "read my book" because I don't have one. A simple explanation or link to more information about my failure would be helpful.
It seems like there must be some problem in the way I call the processVideoFile function, but I can't figure out what I did wrong. Thanks for spending the time to take a look.
main.cpp
#include <iostream>
#include <stdio.h>
#include <string>
#include <time.h>
#include "parseMotion.cpp"
#include "resumepause.cpp"
#include "videoProcess.cpp"
using namespace std;
bool DEBUG = true;
int main(int argc, char **argv) {
//Useful directory strings
string camDir [3];
camDir[0]= "cam01(Outside)/";
camDir[1]= "cam02(Upper)/";
camDir[2]= "cam03(Lower)/";
string latestWD = "/Store/SecurityStorage/LatestVideos/";
string archiveWD = "/Store/SecurityStorage/VideoArchive/";
int threadStatus [3];
threadStatus[0] = 0;
threadStatus[1] = 0;
threadStatus[2] = 0;
//-50 paused
//-1 couldn't connect initially to camera
//0 Not yet started
//1 Started successfully
//2 lost connection to cam - retrying
deque<string> fileDeque;
deque<int> fileTimingDeque;
int exitTrig = -1;
int counter = 0;
FILE *MotionIOStream = popen("motion 2>&1", "r");
if(!MotionIOStream){
exitTrig = 1;
}
while( exitTrig < 0 )
{
//Set maximum length, fgets: get one line
char buffer[1024];
string lineOutput;
lineOutput = fgets(buffer, sizeof(buffer), MotionIOStream);
//check mysqldb for pause/resume
int rpResult;
rpResult = checkSchedule(threadStatus);
if(rpResult != 0)
{
return rpResult;
}
//process video - fork
int pid;
pid = processVideoFiles(fileDeque, fileTimingDeque);
if(pid == 0)
{
return 0;
}
//cout << "Starting to parse" << endl;
parseMotionOutput(lineOutput, threadStatus, fileDeque, fileTimingDeque);
counter++;
//[3] Thread 3 started
if( counter > 20 )
{
exitTrig = 2;
pclose(MotionIOStream);
system("killall motion");
return 0;
}
}
//Handle error returns here.
//case 1: "Couldn't start motion."
//case 2: ""
return 0;
}
Here is videoProcess.cpp:
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <boost/xpressive/xpressive_static.hpp>
using namespace boost::xpressive;
int processVideoFiles( std::deque<std::string> &fileDeque, std::deque<int> &fileTimingDeque )
{
std::time_t secondsNow;
secondsNow = std::time(NULL);
int nextFileSeconds = fileTimingDeque.front();
int diff = secondsNow - nextFileSeconds;
if( diff > 120)
{
//Should fork
int pid = fork();
if(pid == 0){
//Is child
std::string filePath = fileDeque.front();
mark_tag wd(1), camDir(2), dateDir(3), fileName(4);
// /Store/SecurityStorage/LatestVideos/cam03(Lower)/2011-07-21/01-20110721112236.avi
sregex pathRegex = (wd= "/Store/SecurityStorage/LatestVideos/") >> (camDir= ("cam0" >> range('1', '3') >> '/') ) >> (dateDir= ( repeat<4,4>(range('0', '9')) >> '-' >> '0' | '1' >> range( '0', '9' ) >> '/') ) >> (fileName= ( repeat<2,2>(range('0','9')) >> '-' >> repeat<14,14>(range('0','9')) >> '.' >> "avi" ) ) ;
smatch pathWhat;
if( regex_search(filePath, pathWhat, pathRegex) )
{
std::cout << "The working directory for this file is:" << pathWhat[wd] << std::endl;
std::cout << "The camera directory for this file is:" << pathWhat[camDir] << std::endl;
std::cout << "The date directory for this file is:" << pathWhat[dateDir] << std::endl;
std::cout << "The filename of this file is:" << pathWhat[fileName] << std::endl;
}else
{
std::cout << "Error: Couldn't match the file path regex." << std::endl;
return 0;
}
//mplayer $filepath -vo jpeg -ao null -frames 25
std::string commandString = "mplayer " + filePath + " -vo jpeg -ao null -frames 25";
const char* commandChar = commandString.c_str();
int commandResult = system(commandChar);
if(commandResult != 0)
{
std::cout << "Couldn't create jpeg files for some reason" << endl;
}else
{
return 0;
}
//Last steps
fileDeque.pop_front();
fi开发者_运维问答leTimingDeque.pop_front();
}
return pid;
}else
{
return 1;
}
}
The main
definition seems correct, so there has to be an error in one of the included files. Including a .cpp
file is not recommended practice, btw., and not doing that makes these kinds of errors much easier to debug.
As larsmans suggests, this is caused by some stale definition on the previous headers. Try removing them and leaving just one of them to see which one introduces the error. Also, another trick could be to use cpp
directly to produce just one big file, and then edit it into an editor with syntax highlighting to see where you're missing a bracket, etc.:
cpp -Iinclude_dirs main.cpp > output_file.cpp
It seems like you have forgot to put ;
after a class declaration somewhere, or forgot to put a matching }
. The error is most likely in one of your header files that you haven't shown.
Where is the header <deque>
included?
Also, can you put the other two files you are including, in particular the resumepause.cpp
file
精彩评论