Fawkes API  Fawkes Development Version
event_trigger.cpp
1 /***************************************************************************
2  * event_trigger.cpp - Class for handling EventTriggers (such as a subscriber)
3  *
4  *
5  * Created: 7:03:38 PM 2016
6  * Copyright 2016 Frederik Zwilling
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #include "event_trigger.h"
23 
24 #include "event_trigger_manager.h"
25 
26 #include <core/exception.h>
27 
28 /** @class EventTrigger event_trigger.h
29  * Class holding all information about an EventTrigger
30  * @author Frederik Zwilling
31  */
32 
33 /** Constructor.
34  * @param change_stream The change stream for the collection, already moved to the end
35  * @param filter_query The query to use for filtering the change stream
36  * @param ns namespace of the trigger, format db.collection
37  * @param callback Reference to callback function
38  */
39 EventTrigger::EventTrigger(mongocxx::change_stream && change_stream,
40  const bsoncxx::document::view & filter_query,
41  const std::string & ns,
42  const boost::function<void(bsoncxx::document::view)> &callback)
43 : change_stream(std::move(change_stream)),
44  filter_query(filter_query),
45  ns(ns),
46  ns_db(EventTriggerManager::get_db_name(ns)),
47  callback(callback)
48 {
49  if (ns_db == "") {
50  throw fawkes::Exception("Invalid namespace, does not reference database");
51  }
52 }
53 
54 EventTrigger::~EventTrigger()
55 {
56 }
EventTriggerManager
Definition: event_trigger_manager.h:44
EventTrigger::EventTrigger
EventTrigger(mongocxx::change_stream &&change_stream, const bsoncxx::document::view &oplog_query, const std::string &ns, const boost::function< void(bsoncxx::document::view)> &callback)
Constructor.
Definition: event_trigger.cpp:38
fawkes::Exception
Definition: exception.h:39