summaryrefslogtreecommitdiff
path: root/gui/src/threadedChainImageLoader.h
blob: 01f0d0350d50a113b82a27716996fdf53bedb4fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include "ofThread.h"
#include "chainImage.h"
#include "ofURLFileLoader.h"
#include "ofTypes.h" 
#include "ofThreadChannel.h"


using namespace std;

class threadedChainImageLoader : public ofThread {
public:
    threadedChainImageLoader();
    ~threadedChainImageLoader();

	void loadFromDisk(chainImage& image, string file);
	void loadFromURL(chainImage& image, string url);



private:
	void update(ofEventArgs & a);
    virtual void threadedFunction();
	void urlResponse(ofHttpResponse & response);
    
    // Entry to load.
    struct chainImageLoaderEntry {
        chainImageLoaderEntry() {
            image = NULL;
        }
        
        chainImageLoaderEntry(chainImage & pImage) {
            image = &pImage;
        }
        chainImage* image;
        string filename;
        string url;
        string name;
    };


    typedef map<string, chainImageLoaderEntry>::iterator entry_iterator;

	int                 nextID;
    int                 lastUpdate;

	map<string,chainImageLoaderEntry> images_async_loading; // keeps track of images which are loading async
	ofThreadChannel<chainImageLoaderEntry> images_to_load_from_disk;
	ofThreadChannel<chainImageLoaderEntry> images_to_update;
};