50 #define return_sched(retval) \
52 fo_scheduler_disconnect((retval));\
56 int main(
int argc,
char **argv)
59 vector<string> fileNames;
60 string directoryToScan;
61 if (!
parseCliOptions(argc, argv, cliOptions, fileNames, directoryToScan))
70 if (!fileNames.empty())
72 const unsigned long fileNamesCount = fileNames.size();
73 bool fileError =
false;
74 bool printComma =
false;
82 #pragma omp parallel shared(printComma)
85 for (
unsigned int argn = 0; argn < fileNamesCount; ++argn)
87 const string fileName = fileNames[argn];
92 l = agentObj.processFile(fileName);
94 catch (std::runtime_error &e)
96 cerr <<
"Unable to read " << e.what();
100 pair<string, vector<ojomatch>> scanResult(fileName, l);
113 cout << endl <<
"]" << endl;
115 return fileError ? 1 : 0;
117 else if (directoryToScan.length() > 0)
140 if (!
processUploadId(state, uploadId, databaseHandler, ignoreFilesWithMimeType))
Store the options sent through the CLI.
bool doJsonOutput() const
Check if JSON output is required.
bool doignoreFilesWithMimeType() const
Check ignore files with particular mimetype is required.
Store the state of the agent.
const OjoAgent & getOjoAgent() const
void setAgentId(const int agentId)
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.
int queryAgentId(PGconn *dbConn)
Get agent id, exit if agent id is incorrect.
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.
CopyrightState getState(CliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
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.
void appendToJson(const std::string fileName, const std::pair< string, list< match >> resultPair, bool &printComma)
void printResultToStdout(const std::string fileName, const std::pair< string, list< match >> resultPair)
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
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...
char * fo_scheduler_current()
Get the last read string from the scheduler.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
fo_dbManager * dbManager
fo_dbManager object
fo namespace holds the FOSSology library functions.
void scanDirectory(const bool json, const string &directoryPath)
#define return_sched(retval)