1// Aseprite
2// Copyright (C) 2022 Igara Studio S.A.
3// Copyright (C) 2001-2018 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_RES_RESOURCES_LOADER_H_INCLUDED
9#define APP_RES_RESOURCES_LOADER_H_INCLUDED
10#pragma once
11
12#include "base/concurrent_queue.h"
13#include "base/thread.h"
14
15#include <memory>
16
17namespace app {
18
19 class Resource;
20 class ResourcesLoaderDelegate;
21
22 class ResourcesLoader {
23 public:
24 ResourcesLoader(std::unique_ptr<ResourcesLoaderDelegate>&& delegate);
25 ~ResourcesLoader();
26
27 void cancel();
28 bool isDone() const { return m_done; }
29 bool next(std::unique_ptr<Resource>& resource);
30 void reload();
31
32 private:
33 void threadLoadResources();
34 base::thread* createThread();
35
36 typedef base::concurrent_queue<Resource*> Queue;
37
38 std::unique_ptr<ResourcesLoaderDelegate> m_delegate;
39 bool m_done;
40 bool m_cancel;
41 Queue m_queue;
42 std::unique_ptr<base::thread> m_thread;
43 };
44
45} // namespace app
46
47#endif
48