LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
engineimp.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014, Sam Schetterer, Nathan Kutz, University of Washington
3 Authors: Sam Schetterer
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 
10 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11 
12 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 
16 */
17 #ifndef ENGINEIMP_H
18 #define ENGINEIMP_H
19 #include <list>
20 #include <queue>
21 #include <iostream>
22 #include <fstream>
23 #include <stdio.h>
24 #include <thread>
25 #include <mutex>
26 #include <atomic>
27 #include <condition_variable>
28 #include "item_wrapper.h"
29 class engine;
30 class writer;
32  std::map<std::string, input>& inv, engineimp* en);
47 class engineimp{
48  std::thread write_thread;
49  std::mutex data_lock;
50  std::mutex condition_lock;
51  std::condition_variable write_cond;
52  volatile std::atomic_size_t datas_queued;
53  volatile std::atomic_char is_over;
54  void read(std::istream& fstr);
55  void _read(std::istream& fstr);
56  void sort_pp();
57  void execute_command(std::string inval);
58  void update();
60  FILE* ofile;
61  std::map<size_t, std::list<std::shared_ptr<writer>>> writers;
62  std::list<std::map<size_t, std::list<std::shared_ptr<writer>>>> async_write_queue;
63  std::map<std::string, item_wrapper > values;
64  std::map<std::string, input> inputs;
65  std::set<std::shared_ptr<item>> update_vars;
66  public:
67  void write_dat();
68  void add_writer(const std::shared_ptr<writer>& wval);
69  void needs_updating(std::string name);
70  void needs_updating(std::shared_ptr<item> p);
71  size_t index;
73  void remove_item(std::string name);
75  void run();
77  bool item_exists(std::shared_ptr<item> val) const;
78  bool item_exists(const std::string& val) const;
80  engineimp(const std::string& fname, const std::string& outname, const std::string& index);
82  ~engineimp();
83  friend class engine;
84  friend class item;
85  friend class variable;
86  friend item_wrapper eval_lisp(std::string in_cmd, std::string base_name,
87  std::map<std::string, input>& inv, engineimp* en);
88 };
90 struct data_io_info{
91  FILE* file;
92  //list of requested data writes
93  std::list<std::map<size_t, std::list<std::shared_ptr<writer>>>>* writers;
94  volatile std::atomic_size_t* datas_queued;
95  volatile std::atomic_char* is_over;
96 };
97 #endif