Apply clang-format to source tree
[alexxy/gromacs.git] / src / api / cpp / sessionresources.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2018,2019, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS 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 GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35
36 #ifndef GMXAPI_SESSION_RESOURCES_IMPL_H
37 #define GMXAPI_SESSION_RESOURCES_IMPL_H
38
39 /*! \file
40  * \brief Implementation details for SessionResources infrastructure.
41  *
42  * Define the library interface for classes with opaque external interfaces.
43  *
44  * These are specifically details of the gmx Mdrunner session implementation.
45  *
46  * \author M. Eric Irrgang <ericirrgang@gmail.com>
47  * \ingroup gmxapi
48  */
49
50 #include "gmxapi/session/resources.h"
51
52 #include <string>
53
54 #include "gmxapi/md/mdsignals.h"
55 #include "gmxapi/session.h"
56
57 namespace gmxapi
58 {
59
60 /*!
61  * \brief Consumer-specific access to Session resources.
62  *
63  * Each element of work that is managed by a Session and which may need access to Session resources
64  * is uniquely identified. SessionResources objects allow client code to be identified by the
65  * Session so that appropriate resources can be acquired when needed.
66  *
67  * Resources are configured at Session launch by SessionImpl::createResources()
68  *
69  * \ingroup gmxapi
70  */
71 class SessionResources final
72 {
73 public:
74     /*!
75      * \brief Construct a resources object for the named operation.
76      *
77      * \param session implementation object backing these resources.
78      * \param name Unique name of workflow operation.
79      */
80     SessionResources(SessionImpl* session, std::string name);
81
82     /*!
83      * \brief no default constructor.
84      *
85      * \see SessionResources(SessionImpl* session, std::string name)
86      */
87     SessionResources() = delete;
88
89     ///@{
90     /*!
91      * \brief Not moveable or copyable.
92      *
93      * Objects of this type should only exist in their Session container.
94      * If necessary, ownership can be transferred by owning through a unique_ptr handle.
95      */
96     SessionResources(const SessionResources&) = delete;
97     SessionResources& operator=(const SessionResources&) = delete;
98     SessionResources(SessionResources&&)                 = delete;
99     SessionResources& operator=(SessionResources&&) = delete;
100     ///@}
101
102     ~SessionResources();
103
104     /*!
105      * \brief Get the name of the gmxapi operation for which these resources exist.
106      *
107      * \return workflow element name
108      */
109     std::string name() const;
110
111     /*!
112      * \brief Get a Signal instance implementing the requested MD signal.
113      *
114      * The caller is responsible for ensuring that the session is still active.
115      * Unfortunately, there isn't really a way to do that right now. This needs improvemnt
116      * in a near future version.
117      *
118      * Also, this is an external interface that should avoid throwing exceptions for ABI compatibility.
119      *
120      * \param signal currently must be gmxapi::md::signals::STOP
121      * \return callable object.
122      *
123      * Example:
124      *
125      *     auto signal = sessionResources->getMdrunnerSignal(md::signals::STOP);
126      *     signal();
127      *
128      * \throws gmxapi::NotImplementedError if an implementation is not available for the requested signal.
129      * \throws gmxapi::ProtocolError if the Session or Signaller is not available.
130      */
131     Signal getMdrunnerSignal(md::signals signal);
132
133 private:
134     /*!
135      * \brief pointer to the session owning these resources
136      */
137     SessionImpl* sessionImpl_ = nullptr;
138
139     /*!
140      * \brief name of the associated gmxapi operation
141      */
142     std::string name_;
143 };
144
145 } // end namespace gmxapi
146
147 #endif // GMXAPI_SESSION_RESOURCES_IMPL_H