61 #define return_sched(retval) \ 63 fo_scheduler_disconnect((retval));\ 67 int main(
int argc,
char **argv)
70 vector<string> fileNames;
71 string directoryToScan;
72 if (!
parseCliOptions(argc, argv, cliOptions, fileNames, directoryToScan))
81 if (!fileNames.empty())
83 const unsigned long fileNamesCount = fileNames.size();
84 bool fileError =
false;
85 bool printComma =
false;
93 #pragma omp parallel shared(printComma) 96 for (
unsigned int argn = 0; argn < fileNamesCount; ++argn)
98 const string fileName = fileNames[argn];
103 l = agentObj.processFile(fileName);
105 catch (std::runtime_error &e)
107 cerr <<
"Unable to read " << e.what();
111 pair<string, vector<ojomatch>> scanResult(fileName, l);
124 cout << endl <<
"]" << endl;
126 return fileError ? 1 : 0;
128 else if (directoryToScan.length() > 0)
146 int arsId =
writeARS(state, 0, uploadId, 0, dbManager);
151 if (!
processUploadId(state, uploadId, databaseHandler, ignoreFilesWithMimeType))
155 writeARS(state, arsId, uploadId, 1, dbManager);
bool doignoreFilesWithMimeType() const
Check ignore files with particular mimetype is required.
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
#define return_sched(retval)
void printResultToStdout(const std::string fileName, const std::pair< string, list< match >> resultPair)
void scanDirectory(const bool json, const string &directoryPath)
char * fo_scheduler_current()
Get the last read string from the scheduler.
CopyrightState getState(CliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
const OjoAgent & getOjoAgent() const
void appendToJson(const std::string fileName, const std::pair< string, list< match >> resultPair, bool &printComma)
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
Store the state of the agent.
void setAgentId(const int agentId)
bool processUploadId(const CopyrightState &state, int agentId, int uploadId, CopyrightDatabaseHandler &databaseHandler, bool ignoreFilesWithMimeType)
Process a given upload id, scan from statements and add to database.
bool parseCliOptions(int argc, char **argv, CliOptions &dest, std::vector< std::string > &fileNames, std::string &directoryToScan)
Parse the options sent by CLI to CliOptions object.
fo_dbManager * dbManager
fo_dbManager object
int queryAgentId(PGconn *dbConn)
Get agent id, exit if agent id is incorrect.
fo namespace holds the FOSSology library functions.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
bool doJsonOutput() const
Check if JSON output is required.
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.
Store the options sent through the CLI.