btc-ag / service-idl

Xtext-based Service IDL (Interface Definition Language) and Code Generators for Protobuf, C++, Java and .NET
Eclipse Public License 2.0
8 stars 8 forks source link

Complete generation of event-related code in ServiceAPI and Dispatcher #161

Closed sigiesec closed 6 years ago

sigiesec commented 6 years ago

In Dispatcher (The class C***Dispatcher):

The API

isabusar commented 6 years ago

An example for the following event in Idl: event DataModelChanged [guid = 9BFE9AB7-3AA6-441F-82D7-D1A27F6321CE] (DataModelEventArgs);

the actuel added code in Dispatcher: Member attribute: Commons::Core::UniquePtr<Commons::CoreExtras::IObserver<ServiceAPI::DataModelEventArgs>> remoteDataModelEventPublisher;

in AttachEndpoint: void CFieldDataDispatcher::AttachEndpoint(BTC::ServiceComm::API::IServerEndpoint &endpoint) { ... this->remoteDataModelEventPublisher = CreateRemoteEventPublisher<ServiceAPI::DataModelEventArgs, Protobuf::DataModelEventArgs>(endpoint); }

template<typename ServiceEventT, typename ProtoEventT>
BTC::Commons::Core::UniquePtr<Commons::CoreExtras::IObserver<ServiceEventT>> CFieldDataDispatcher::CreateRemoteEventPublisher(
  ServiceComm::API::IServerEndpoint& endpoint) {
  return ServiceComm::Util::CreateRemoteEventPublisher<ServiceEventT>(
    GetDispatchee(),
    endpoint.GetEventRegistry(),
    [this](ServiceEventT const& event) -> ServiceComm::Commons::MessagePtr {
      return MarshalEvent<ServiceEventT, ProtoEventT>(event);
    },
    ServiceEventT::EVENT_TYPE_GUID());
}
template<typename ServiceEventT, typename ProtoEventT>
ServiceComm::Commons::MessagePtr CFieldDataDispatcher::MarshalEvent(const ServiceEventT& serviceEvent) {
  ServiceComm::Commons::MessagePtr message(GetMessagePool().Borrow());
  ProtoEventT eventProtobuf;
  FieldLink::Protobuf::FieldDataCodec::Encode(serviceEvent, &eventProtobuf);
  message->PushBack(ServiceComm::ProtobufUtil::ProtobufSupport::ProtobufToMessagePart(GetMessagePartPool(), eventProtobuf));
  return Move(message);
}

in DeleteEndpoint: void CFieldDataDispatcher::DetachEndpoint(BTC::ServiceComm::API::IServerEndpoint &endpoint) { this->remoteDataPointValueDoubleEventPublisher.Clear(); ... }

And for the Interface: class IFieldData : public virtual Commons::CoreExtras::IObservableRegistration<DataModelEventArgs>, ... { ... }

sigiesec commented 6 years ago

@isabusar Thanks for providing this information!