Added database abstractions
[gnucomo.git] / src / lib / object.cpp
1
2 /**************************************************************************
3 **  (c) Copyright 2002, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : object.cpp
10 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
11 **      VERSION NUMBER : $Revision: 1.1 $
12 **
13 **  DESCRIPTION      :  Implementation of the Object class
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Jul 08, 2005
23 **      LAST UPDATE     : Jul 08, 2005
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: object.cpp,v $
29    Revision 1.1  2007-01-11 13:49:54  arjen
30    Experimental start of database OO abstraction layer.
31
32 *****************************/
33
34 static const char *RCSID = "$Id: object.cpp,v 1.1 2007-01-11 13:49:54 arjen Exp $";
35
36 #include "object.h"
37
38 extern std::ostream *Log;
39
40 /*=========================================================================
41 **  NAME           : Object
42 **  SYNOPSIS       : Object(gnucomo_database &db);
43 **  PARAMETERS     : 
44 **  RETURN VALUE   : Object constructor.
45 **
46 **  DESCRIPTION    : Create a new Object for which there is no representation
47 **                   in the database.
48 **
49 **  VARS USED      :
50 **  VARS CHANGED   :
51 **  FUNCTIONS USED :
52 **  SEE ALSO       :
53 **  LAST MODIFIED  : Jul 08, 2005
54 **=========================================================================
55 */
56
57 Object::Object(gnucomo_database &gdb) : database_entity(gdb, "object")
58 {
59    id = "0";
60    hostname = "";
61 }
62
63 Object::Object(gnucomo_database &gdb, String name) : database_entity(gdb, "object")
64 {
65    id = "0";
66    hostname = name;
67
68    String objectid("");
69    String check_host;
70
71    check_host += "objectname = '";
72    check_host += hostname;
73    check_host += "'";
74
75    if (find_one(check_host) > 0)
76    {
77       id = fields["objectid"];
78       std::cerr << "Object id = " << id << "\n";
79    }
80
81 }
82
83 std::list<ObjectLog> Object::select_logs(UTC start, UTC finish, String service)
84 {
85
86    int  rows_found;
87    std::list<ObjectLog> logs;
88
89    String where("objectid=");
90
91    where += id;
92    where += " and timestamp >= '";
93    where += start.format();
94    where += "' and timestamp <= '";
95    where += finish.format();
96    where += "' and servicecode = '";
97    where += service;
98    where += "'";
99
100    rows_found = find_many("log", where);
101
102    for (int r = 0; r < rows_found; r++)
103    {
104       ObjectLog ol(this, r);
105       logs.push_back(ol);
106    }
107
108    return logs;
109 }