• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ICOMMUNICATORAGGREGATOR_H
17 #define ICOMMUNICATORAGGREGATOR_H
18 
19 #include <cstdint>
20 #include "iadapter.h"
21 #include "ref_object.h"
22 #include "communicator_type_define.h"
23 
24 namespace DistributedDB {
25 class ICommunicator; // Forward Declaration
26 // Return E_OK to indicate to retain received frame. Do not block during callback.
27 using CommunicatorLackCallback = std::function<int(const LabelType &commLabel, const std::string &userId)>;
28 
29 class ICommunicatorAggregator : public virtual RefObject {
30 public:
31     // Return 0 as success. Return negative as error
32     // The caller is the owner of inAdapter and responsible for manage its lifecycle.
33     // The ICommunicatorAggregator is only the user of inAdapter
34     // If Initialize fail, the ICommunicatorAggregator will rollback what had done to inAdapter so it can be reuse.
35     virtual int Initialize(IAdapter *inAdapter) = 0;
36 
37     // Call this method after Initialize successfully and before destroy the ICommunicatorAggregator
38     // Emphasize again : DO NOT CALL Finalize IF Initialize FAIL.
39     // Must not call any other functions if Finalize had been called.
40     // More likely, The Finalize has no chance to be called. since it is process level.
41     virtual void Finalize() = 0;
42 
43     // If not success, return nullptr and set outErrorNo
44     virtual ICommunicator *AllocCommunicator(uint64_t commLabel, int &outErrorNo) = 0;
45     virtual ICommunicator *AllocCommunicator(const LabelType &commLabel, int &outErrorNo) = 0;
46     virtual void ReleaseCommunicator(ICommunicator *inCommunicator) = 0;
47     virtual int RegCommunicatorLackCallback(const CommunicatorLackCallback &onCommLack, const Finalizer &inOper) = 0;
48     virtual int RegOnConnectCallback(const OnConnectCallback &onConnect, const Finalizer &inOper) = 0;
49     virtual int GetLocalIdentity(std::string &outTarget) const = 0;
~ICommunicatorAggregator()50     virtual ~ICommunicatorAggregator() {};
51 };
52 } // namespace DistributedDB
53 
54 #endif // ICOMMUNICATORAGGREGATOR_H
55