55 #include "copyright.hpp" 60 #define return_sched(retval) \ 62 fo_scheduler_disconnect((retval));\ 66 int main(
int argc,
char** argv)
72 vector<string> fileNames;
73 string directoryToScan;
74 if (!
parseCliOptions(argc, argv, cliOptions, fileNames, directoryToScan))
83 if (!fileNames.empty())
85 const unsigned long fileNamesCount = fileNames.size();
86 bool fileError =
false;
87 bool printComma =
false;
97 for (
unsigned int argn = 0; argn < fileNamesCount; ++argn)
99 const string fileName = fileNames[argn];
109 if (scanResult.first.empty())
117 cout << endl <<
"]" << endl;
119 return fileError ? 1 : 0;
121 else if (directoryToScan.length() > 0)
131 if (!copyrightDatabaseHandler.createTables())
133 std::cout <<
"FATAL: initialization failed" << std::endl;
141 if (uploadId <= 0)
continue;
148 if (!
processUploadId(state, agentId, uploadId, copyrightDatabaseHandler, ignoreFilesWithMimeType))
#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)
bool doignoreFilesWithMimeType() const
Check to ignore files with particular mimetype.
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.
void appendToJson(const std::string fileName, const std::pair< string, list< match >> resultPair, bool &printComma)
bool doJsonOutput() const
Check if JSON output is required.
Manages database related requests for agent.
Holds information about state of one agent.
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...
Store the options sent through the CLI.
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.
pair< string, list< match > > processSingleFile(const CopyrightState &state, const string fileName)