1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "include/flutter/engine_method_result.h" 6 7 #include <assert.h> 8 #include <iostream> 9 10 namespace flutter { 11 namespace internal { 12 ReplyManager(BinaryReply reply_handler)13ReplyManager::ReplyManager(BinaryReply reply_handler) 14 : reply_handler_(std::move(reply_handler)) { 15 assert(reply_handler_); 16 } 17 ~ReplyManager()18ReplyManager::~ReplyManager() { 19 if (reply_handler_) { 20 // Warn, rather than send a not-implemented response, since the engine may 21 // no longer be valid at this point. 22 std::cerr 23 << "Warning: Failed to respond to a message. This is a memory leak." 24 << std::endl; 25 } 26 } 27 SendResponseData(const std::vector<uint8_t> * data)28void ReplyManager::SendResponseData(const std::vector<uint8_t>* data) { 29 if (!reply_handler_) { 30 std::cerr 31 << "Error: Only one of Success, Error, or NotImplemented can be " 32 "called," 33 << " and it can be called exactly once. Ignoring duplicate result." 34 << std::endl; 35 return; 36 } 37 38 const uint8_t* message = data && !data->empty() ? data->data() : nullptr; 39 size_t message_size = data ? data->size() : 0; 40 reply_handler_(message, message_size); 41 reply_handler_ = nullptr; 42 } 43 44 } // namespace internal 45 } // namespace flutter 46