44 #include "copyright.hpp"
49 #define return_sched(retval) \
51 fo_scheduler_disconnect((retval));\
55 int main(
int argc,
char** argv)
61 vector<string> fileNames;
62 string directoryToScan;
63 if (!
parseCliOptions(argc, argv, cliOptions, fileNames, directoryToScan))
71 if (!fileNames.empty())
73 const unsigned long fileNamesCount = fileNames.size();
74 bool fileError =
false;
75 bool printComma =
false;
83 #pragma omp parallel num_threads(THREADS)
86 for (
unsigned int argn = 0; argn < fileNamesCount; ++argn)
88 const string fileName = fileNames[argn];
98 if (scanResult.first.empty())
106 cout << endl <<
"]" << endl;
108 return fileError ? 1 : 0;
110 else if (directoryToScan.length() > 0)
122 if (!copyrightDatabaseHandler.createTables())
124 std::cout <<
"FATAL: initialization failed" << std::endl;
132 if (uploadId <= 0)
continue;
139 if (!
processUploadId(state, agentId, uploadId, copyrightDatabaseHandler, ignoreFilesWithMimeType))
Store the options sent through the CLI.
bool doJsonOutput() const
Check if JSON output is required.
bool doignoreFilesWithMimeType() const
Check to ignore files with particular mimetype.
Manages database related requests for agent.
Holds information about state of one agent.
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.
pair< string, list< match > > processSingleFile(const CopyrightState &state, const string fileName)
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 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)