Fix changelog email address
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-rail / icon.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Window Icon Cache
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <freerdp/utils/stream.h>
21 #include <freerdp/utils/memory.h>
22 #include <freerdp/utils/hexdump.h>
23 #include <freerdp/utils/unicode.h>
24
25 #include <freerdp/rail/icon.h>
26
27 ICON_INFO* icon_cache_get(rdpIconCache* cache, uint8 id, uint16 index, void** extra)
28 {
29         ICON_INFO* entry;
30
31         if (id >= cache->numCaches)
32         {
33                 printf("invalid window icon cache id:%d\n", id);
34                 return (ICON_INFO*) NULL;
35         }
36
37         if (index >= cache->numCacheEntries)
38         {
39                 printf("invalid window icon cache index:%d in cache id:%d\n", index, id);
40                 return (ICON_INFO*) NULL;
41         }
42
43         entry = cache->caches[id].entries[index].entry;
44
45         if (extra != NULL)
46                 *extra = cache->caches[id].entries[index].extra;
47
48         return entry;
49 }
50
51 void icon_cache_put(rdpIconCache* cache, uint8 id, uint16 index, ICON_INFO* entry, void* extra)
52 {
53         if (id >= cache->numCaches)
54         {
55                 printf("invalid window icon cache id:%d\n", id);
56                 return;
57         }
58
59         if (index >= cache->numCacheEntries)
60         {
61                 printf("invalid window icon cache index:%d in cache id:%d\n", index, id);
62                 return;
63         }
64
65         cache->caches[id].entries[index].entry = entry;
66
67         if (extra != NULL)
68                 cache->caches[id].entries[index].extra = extra;
69 }
70
71 rdpIconCache* icon_cache_new(rdpRail* rail)
72 {
73         rdpIconCache* cache;
74
75         cache = (rdpIconCache*) xzalloc(sizeof(rdpIconCache));
76
77         if (cache != NULL)
78         {
79                 int i;
80
81                 cache->rail = rail;
82                 cache->numCaches = (uint8) rail->settings->num_icon_cache_entries;
83                 cache->numCacheEntries = rail->settings->num_icon_cache_entries;
84
85                 cache->caches = xzalloc(cache->numCaches * sizeof(WINDOW_ICON_CACHE));
86
87                 for (i = 0; i < cache->numCaches; i++)
88                 {
89                         cache->caches[i].entries = xzalloc(cache->numCacheEntries * sizeof(rdpIconCache));
90                 }
91         }
92
93         return cache;
94 }
95
96 void icon_cache_free(rdpIconCache* cache)
97 {
98         if (cache != NULL)
99         {
100                 int i;
101
102                 for (i = 0; i < cache->numCaches; i++)
103                 {
104                         xfree(cache->caches[i].entries);
105                 }
106
107                 xfree(cache->caches);
108
109                 xfree(cache);
110         }
111 }
112