FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ninka.cc
1 /*
2  * Copyright (C) 2014-2015, Siemens AG
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  */
17 
18 #include "ninka.hpp"
19 
20 using namespace fo;
21 
22 int main(int argc, char** argv)
23 {
24  /* before parsing argv and argc make sure */
25  /* to initialize the scheduler connection */
26 
27  DbManager dbManager(&argc, argv);
28  NinkaDatabaseHandler databaseHandler(dbManager);
29 
30  State state = getState(dbManager);
31 
32  while (fo_scheduler_next() != NULL)
33  {
34  int uploadId = atoi(fo_scheduler_current());
35 
36  if (uploadId == 0) continue;
37 
38  int arsId = writeARS(state, 0, uploadId, 0, dbManager);
39 
40  if (arsId <= 0)
41  bail(5);
42 
43  if (!processUploadId(state, uploadId, databaseHandler))
44  bail(2);
45 
47  writeARS(state, arsId, uploadId, 1, dbManager);
48  }
50 
51  /* do not use bail, as it would prevent the destructors from running */
53  return 0;
54 }
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
DB wrapper for agents.
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 fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
Definition: state.hpp:26
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.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
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...
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.