summaryrefslogtreecommitdiff
path: root/idlc/cpp_gen/cpp_stub_header_gen_cb.h
blob: 8cb4c1ff0ba9a9725dfa33af26592c7c04754231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
#define IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_

const char CB_EXCEPTIONS[] =
R"__cpp_cb(
class Exception {};
class NotConnectedSocketException : public Exception {};
class InvalidProtocolException : public Exception {};
class InvalidIOException : public Exception {};
class InvalidCallbackException : public Exception {};
)__cpp_cb";

const char CB_PRIVATE_MEMBERS[] =
R"__cpp_cb(  static void OnConnectedCB(const char* sender, const char* instance, void* data);
  static void OnDisconnectedCB(const char* sender, const char* instance, void* data);
  static int OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void* data);

  rpc_port_stub_h stub_;
  std::shared_ptr<ServiceBase::Factory> service_factory_;
  std::list<std::shared_ptr<ServiceBase>> services_;
)__cpp_cb";

const char CB_SERVICE_BASE_FRONT[] =
R"__cpp_cb(
  class ServiceBase {
   public:
    class Factory {
     public:
      /// <summary>
      /// The method for making service instances
      /// </summary>
      /// <param name="sender">The client app ID</param>
      /// <param name="instance">The client instance ID</param>
      virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
    };

    virtual ~ServiceBase() = default;

    /// <summary>
    /// Gets client app ID
    /// </summary>
    const std::string& GetSender() const {
      return sender_;
    }

    /// <summary>
    /// Gets client instance ID
    /// </summary>
    const std::string& GetInstance() const {
      return instance_;
    }

    /// <summary>
    /// This method will be called when the client is connected
    /// </summary>
    virtual void OnCreate() = 0;

    /// <summary>
    /// This method will be called when the client is disconnected
    /// </summary>
    virtual void OnTerminate() = 0;

)__cpp_cb";

const char CB_SERVICE_BASE_BACK[] =
R"__cpp_cb(
   protected:
    ServiceBase(std::string sender, std::string instance);

   private:
    std::string sender_;
    std::string instance_;
  };)__cpp_cb";

const char CB_PUBLIC_METHODS[] =
R"__cpp_cb(  ##();
  ~##();

  /// <summary>
  /// Listens to client apps
  /// </summary>
  /// <param name="service_factory">The factory object for making service instances</param>
  /// <exception cref="InvalidIOException">
  /// Thrown when internal I/O error happen.
  /// </exception>
  void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);

  /// <summary>
  /// Gets service objects which are connected
  /// </summary>
  /// <returns>The list of service objects which are connected</returns>
  const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
    return services_;
  }

)__cpp_cb";

const char CB_HEADER[] =
R"__cpp_cb(
#pragma once

#include <bundle.h>
#include <rpc-port-parcel.h>
#include <rpc-port.h>

#include <memory>
#include <string>
#include <vector>
#include <list>
#include <atomic>

)__cpp_cb";

#endif  // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_