Blue Brain BioExplorer
AddModelFromBlobTask.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  * Responsible Author: Daniel.Nachbaur@epfl.ch
5  *
6  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 3.0 as published
10  * by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
27 
28 namespace core
29 {
30 struct BinaryParam;
31 }
32 SERIALIZATION_ACCESS(BinaryParam)
33 
34 namespace core
35 {
36 struct Chunk
37 {
38  std::string id;
39 };
40 
42 {
43  size_t size{0};
44  std::string type;
45  std::string chunksID;
47 };
48 
53 class AddModelFromBlobTask : public Task<ModelDescriptorPtr>
54 {
55 public:
56  AddModelFromBlobTask(const BinaryParam& param, Engine& engine);
57 
58  void appendBlob(const std::string& blob);
59 
60 private:
61  void _checkValidity(Engine& engine);
62  void _cancel() final { _chunkEvent.set_exception(std::make_exception_ptr(async::task_canceled())); }
63  float _progressBytes() const { return CHUNK_PROGRESS_WEIGHT * ((float)_receivedBytes / _param.size); }
64 
65  async::event_task<Blob> _chunkEvent;
66  async::event_task<ModelDescriptorPtr> _errorEvent;
67  std::vector<async::task<ModelDescriptorPtr>> _finishTasks;
68  uint8_ts _blob;
69  BinaryParam _param;
70  size_t _receivedBytes{0};
71  const float CHUNK_PROGRESS_WEIGHT{0.5f};
72 };
73 } // namespace core
#define SERIALIZATION_FRIEND(type)
Definition: Macros.h:32
#define SERIALIZATION_ACCESS(type)
Definition: Macros.h:25
AddModelFromBlobTask(const BinaryParam &param, Engine &engine)
void appendBlob(const std::string &blob)
Provides an abstract implementation of a ray-tracing engine.
Definition: Engine.h:59
The ModelParams class represents the parameters needed for initializing a model instance.
Definition: Model.h:178
std::vector< uint8_t > uint8_ts
Definition: Types.h:49
std::string type
file extension or type (MESH, POINTS, CIRCUIT)
size_t size
size in bytes of file