// Copyright 2022 Google LLC // // 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 // // https://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 THIRD_PARTY_NEARBY_SHARING_OUTGOING_SHARE_SESSION_H_ #define THIRD_PARTY_NEARBY_SHARING_OUTGOING_SHARE_SESSION_H_ #include #include // NOLINT #include #include #include #include #include #include "sharing/internal/public/context.h" #include "sharing/nearby_connection.h" #include "sharing/nearby_connections_manager.h" #include "sharing/nearby_connections_types.h" #include "sharing/nearby_file_handler.h" #include "sharing/share_session.h" #include "sharing/share_target.h" #include "sharing/transfer_metadata.h" namespace nearby::sharing { // A description of the outgoing connection to a remote device. class OutgoingShareTargetInfo : public ShareTargetInfo { public: OutgoingShareTargetInfo(std::string endpoint_id, const ShareTarget& share_target, std::function transfer_update_callback); OutgoingShareTargetInfo(OutgoingShareTargetInfo&&); OutgoingShareTargetInfo& operator=(OutgoingShareTargetInfo&&); ~OutgoingShareTargetInfo() override; bool IsIncoming() const override { return false; } const std::optional& obfuscated_gaia_id() const { return obfuscated_gaia_id_; } void set_obfuscated_gaia_id(std::string obfuscated_gaia_id) { obfuscated_gaia_id_ = std::move(obfuscated_gaia_id); } const std::vector& text_payloads() const { return text_payloads_; } const std::vector& wifi_credentials_payloads() const { return wifi_credentials_payloads_; } const std::vector& file_payloads() const { return file_payloads_; } Status connection_layer_status() const { return connection_layer_status_; } void set_connection_layer_status(Status status) { connection_layer_status_ = status; } std::vector GetFilePaths() const; void CreateTextPayloads(); void CreateWifiCredentialsPayloads(); // Create file payloads and update the file size of all file attachments. // The list of file infos must be sorted in the same order as the file // attachments in the share target. // Returns true if all file payloads are created successfully. bool CreateFilePayloads( const std::vector& files); // Create a payload status listener to send status change to // |update_callback|. Send all payloads to NearbyConnectionManager. void SendAllPayloads( Context* context, NearbyConnectionsManager& connection_manager, std::function update_callback); // Create a payload status listener to send status change to // |update_callback|. void InitSendPayload( Context* context, NearbyConnectionsManager& connection_manager, std::function update_callback); // Send the next payload to NearbyConnectionManager. void SendNextPayload(NearbyConnectionsManager& connection_manager); void WriteProgressUpdateFrame(std::optional start_transfer, std::optional progress); // Returns true if the introduction frame is written successfully. bool WriteIntroductionFrame(); protected: void InvokeTransferUpdateCallback(const TransferMetadata& metadata) override; bool OnNewConnection(NearbyConnection* connection) override; private: std::vector ExtractTextPayloads(); std::vector ExtractFilePayloads(); std::vector ExtractWifiCredentialsPayloads(); std::optional ExtractNextPayload(); bool FillIntroductionFrame( nearby::sharing::service::proto::IntroductionFrame* introduction) const; std::optional obfuscated_gaia_id_; // All payloads are in the same order as the attachments in the share target. std::vector text_payloads_; std::vector file_payloads_; std::vector wifi_credentials_payloads_; Status connection_layer_status_; std::function transfer_update_callback_; }; } // namespace nearby::sharing #endif // THIRD_PARTY_NEARBY_SHARING_OUTGOING_SHARE_SESSION_H_