Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafRpcServerApplication.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) 2021- Kontur AS
5 //
6 // GNU Lesser General Public License Usage
7 // This library is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation; either version 2.1 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
17 // for more details.
18 //
19 #pragma once
20 
21 #include "cafNotNull.h"
22 #include "cafRpcApplication.h"
23 #include "cafSession.h"
24 
25 #include <memory>
26 
27 namespace caffa
28 {
29 
30 namespace rpc
31 {
32 
34  {
35  public:
36  ServerApplication( unsigned capability );
38 
39  static ServerApplication* instance();
40 
41  virtual int portNumber() const = 0;
42  virtual void run() = 0;
43  virtual void quit() = 0;
44  virtual bool running() const = 0;
45 
46  virtual std::shared_ptr<Document> document( const std::string& documentId, const caffa::Session* session ) = 0;
47  virtual std::shared_ptr<const Document> document( const std::string& documentId,
48  const caffa::Session* session ) const = 0;
49  virtual std::list<std::shared_ptr<Document>> documents( const caffa::Session* session ) = 0;
50  virtual std::list<std::shared_ptr<const Document>> documents( const caffa::Session* session ) const = 0;
51 
52  virtual std::list<std::shared_ptr<caffa::Document>> defaultDocuments() const = 0;
53 
54  bool requiresValidSession() const;
55  void setRequiresValidSession( bool requiresValidSession );
56 
57  virtual bool readyForSession( caffa::Session::Type type ) const = 0;
58  virtual caffa::SessionMaintainer createSession( caffa::Session::Type type ) = 0;
59  virtual bool hasActiveSessions() const = 0;
60  virtual caffa::SessionMaintainer getExistingSession( const std::string& sessionUuid ) = 0;
61  virtual caffa::ConstSessionMaintainer getExistingSession( const std::string& sessionUuid ) const = 0;
62  virtual void changeSession( caffa::not_null<caffa::Session*> session, caffa::Session::Type newType ) = 0;
63  virtual void destroySession( const std::string& sessionUuid ) = 0;
64 
65  protected:
66  virtual void onStartup() {}
67  virtual void onShutdown() {}
68 
69  private:
70  bool m_requiresValidSession;
71  };
72 } // namespace rpc
73 } // namespace caffa
AppCapability
Application capability Defines what type of application it is. These flags can be combined...
Definition: cafApplication.h:46
Definition: cafSession.h:81
Definition: cafRpcServerApplication.h:33
Definition: cafSession.h:97
Abstract class representing an application session.
Definition: cafSession.h:35
Definition: cafRpcApplication.h:27
Main Caffa namespace.
Definition: cafApplication.h:30