xref: /freebsd/contrib/kyua/drivers/scan_results.hpp (revision d65cd7a57bf0600b722afc770838a5d0c1c3a8e1)
1 // Copyright 2011 The Kyua Authors.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 //   notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 //   notice, this list of conditions and the following disclaimer in the
12 //   documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 //   may be used to endorse or promote products derived from this software
15 //   without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 /// \file drivers/scan_results.hpp
30 /// Driver to scan the contents of a results file.
31 ///
32 /// This driver module implements the logic to scan the contents of a results
33 /// file and to notify the presentation layer as soon as data becomes
34 /// available.  This is to prevent reading all the data from the file at once,
35 /// which could take too much memory.
36 
37 #if !defined(DRIVERS_SCAN_RESULTS_HPP)
38 #define DRIVERS_SCAN_RESULTS_HPP
39 
40 extern "C" {
41 #include <stdint.h>
42 }
43 
44 #include <set>
45 
46 #include "engine/filters.hpp"
47 #include "model/context_fwd.hpp"
48 #include "store/read_transaction_fwd.hpp"
49 #include "utils/datetime_fwd.hpp"
50 #include "utils/fs/path_fwd.hpp"
51 
52 namespace drivers {
53 namespace scan_results {
54 
55 
56 /// Tuple containing the results of this driver.
57 class result {
58 public:
59     /// Filters that did not match any available test case.
60     ///
61     /// The presence of any filters here probably indicates a usage error.  If a
62     /// test filter does not match any test case, it is probably a typo.
63     std::set< engine::test_filter > unused_filters;
64 
65     /// Initializer for the tuple's fields.
66     ///
67     /// \param unused_filters_ The filters that did not match any test case.
68     result(const std::set< engine::test_filter >& unused_filters_) :
69         unused_filters(unused_filters_)
70     {
71     }
72 };
73 
74 
75 /// Abstract definition of the hooks for this driver.
76 class base_hooks {
77 public:
78     virtual ~base_hooks(void) = 0;
79 
80     virtual void begin(void);
81 
82     /// Callback executed when the context is loaded.
83     ///
84     /// \param context The context loaded from the database.
85     virtual void got_context(const model::context& context) = 0;
86 
87     /// Callback executed when a test results is found.
88     ///
89     /// \param iter Container for the test result's data.  Some of the data are
90     ///     lazily fetched, hence why we receive the object instead of the
91     ///     individual elements.
92     virtual void got_result(store::results_iterator& iter) = 0;
93 
94     virtual void end(const result& r);
95 };
96 
97 
98 result drive(const utils::fs::path&, const std::set< engine::test_filter >&,
99              base_hooks&);
100 
101 
102 }  // namespace scan_results
103 }  // namespace drivers
104 
105 #endif  // !defined(DRIVERS_SCAN_RESULTS_HPP)
106