Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_asset.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: afd23e9fa0de0d2900ba87b8233e22242fe15c85 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Blender Foundation (2015)
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/makesrna/intern/rna_asset.c
 *  \ingroup RNA
 */

#include "BLI_utildefines.h"
#include "BLI_fileops_types.h"
#include "BLI_path_util.h"

#include "DNA_space_types.h"

#include "RNA_define.h"
#include "RNA_enum_types.h"

#include "rna_internal.h"

#include "BKE_asset_engine.h"
#include "BKE_idprop.h"

#include "WM_types.h"

#ifdef RNA_RUNTIME

#include "MEM_guardedalloc.h"

#include "RNA_access.h"

#include "BKE_context.h"
#include "BKE_report.h"


/* Asset listing... */

/* Revisions. */
static int rna_AssetRevision_size_get(PointerRNA *ptr)
{
	FileDirEntryRevision *revision = ptr->data;
	return (int)revision->size;
}

static void rna_AssetRevision_size_set(PointerRNA *ptr, const int val)
{
	FileDirEntryRevision *revision = ptr->data;
	revision->size = (int64_t)val;
}

static int rna_AssetRevision_timestamp_get(PointerRNA *ptr)
{
	FileDirEntryRevision *revision = ptr->data;
	return (int)revision->time;
}

static void rna_AssetRevision_timestamp_set(PointerRNA *ptr, const int val)
{
	FileDirEntryRevision *revision = ptr->data;
	revision->time = (int64_t)val;
}

/* Variants. */
static FileDirEntryRevision *rna_AssetVariant_revisions_add(FileDirEntryVariant *variant/*, ReportList *reports,*/)
{
	FileDirEntryRevision *revision = MEM_callocN(sizeof(*revision), __func__);

	BLI_addtail(&variant->revisions, revision);
	variant->nbr_revisions++;

	return revision;
}

static PointerRNA rna_AssetVariant_active_revision_get(PointerRNA *ptr)
{
	FileDirEntryVariant *variant = ptr->data;
	return rna_pointer_inherit_refine(ptr, &RNA_AssetRevision, BLI_findlink(&variant->revisions, variant->act_revision));
}

static void rna_AssetVariant_active_revision_set(PointerRNA *ptr, PointerRNA value)
{
	FileDirEntryVariant *variant = ptr->data;
	FileDirEntryRevision *revision = value.data;

	variant->act_revision = BLI_findindex(&variant->revisions, revision);
}

static void rna_AssetVariant_name_get(struct PointerRNA *ptr, char *value)
{
	FileDirEntryVariant *variant = ptr->data;
	if (variant->name) {
		strcpy(value, variant->name);
	}
	else {
		*value = '\0';
	}
}

static int rna_AssetVariant_name_length(struct PointerRNA *ptr)
{
	FileDirEntryVariant *variant = ptr->data;
	return variant->name ? strlen(variant->name) : 0;
}

static void rna_AssetVariant_name_set(struct PointerRNA *ptr, const char *value)
{
	FileDirEntryVariant *variant = ptr->data;
	MEM_SAFE_FREE(variant->name);
	if (value[0] != '\0') {
		variant->name = BLI_strdup(value);
	}
}

static void rna_AssetVariant_description_get(struct PointerRNA *ptr, char *value)
{
	FileDirEntryVariant *variant = ptr->data;
	if (variant->description) {
		strcpy(value, variant->description);
	}
	else {
		*value = '\0';
	}
}

static int rna_AssetVariant_description_length(struct PointerRNA *ptr)
{
	FileDirEntryVariant *variant = ptr->data;
	return variant->description ? strlen(variant->description) : 0;
}

static void rna_AssetVariant_description_set(struct PointerRNA *ptr, const char *value)
{
	FileDirEntryVariant *variant = ptr->data;
	MEM_SAFE_FREE(variant->description);
	if (value[0] != '\0') {
		variant->description = BLI_strdup(value);
	}
}

/* Entries. */
static PointerRNA rna_AssetEntry_active_variant_get(PointerRNA *ptr)
{
	FileDirEntry *entry = ptr->data;
	return rna_pointer_inherit_refine(ptr, &RNA_AssetVariant, BLI_findlink(&entry->variants, entry->act_variant));
}

static void rna_AssetEntry_active_variant_set(PointerRNA *ptr, PointerRNA value)
{
	FileDirEntry *entry = ptr->data;
	FileDirEntryVariant *variant = value.data;

	entry->act_variant = BLI_findindex(&entry->variants, variant);
}

static FileDirEntryVariant *rna_AssetEntry_variants_add(FileDirEntry *entry/*, ReportList *reports,*/)
{
	FileDirEntryVariant *variant = MEM_callocN(sizeof(*variant), __func__);

	BLI_addtail(&entry->variants, variant);
	entry->nbr_variants++;

	return variant;
}

static void rna_AssetEntry_relpath_get(struct PointerRNA *ptr, char *value)
{
	FileDirEntry *entry = ptr->data;
	if (entry->relpath) {
		strcpy(value, entry->relpath);
	}
	else {
		*value = '\0';
	}
}

static int rna_AssetEntry_relpath_length(struct PointerRNA *ptr)
{
	FileDirEntry *entry = ptr->data;
	return entry->relpath ? strlen(entry->relpath) : 0;
}

static void rna_AssetEntry_relpath_set(struct PointerRNA *ptr, const char *value)
{
	FileDirEntry *entry = ptr->data;
	if (entry->relpath) {
		MEM_freeN(entry->relpath);
	}
	entry->relpath = BLI_strdup(value);
}

static void rna_AssetEntry_name_get(struct PointerRNA *ptr, char *value)
{
	FileDirEntry *entry = ptr->data;
	if (entry->name) {
		strcpy(value, entry->name);
	}
	else {
		*value = '\0';
	}
}

static int rna_AssetEntry_name_length(struct PointerRNA *ptr)
{
	FileDirEntry *entry = ptr->data;
	return entry->name ? strlen(entry->name) : 0;
}

static void rna_AssetEntry_name_set(struct PointerRNA *ptr, const char *value)
{
	FileDirEntry *entry = ptr->data;
	MEM_SAFE_FREE(entry->name);
	if (value[0] != '\0') {
		entry->name = BLI_strdup(value);
	}
}

static void rna_AssetEntry_description_get(struct PointerRNA *ptr, char *value)
{
	FileDirEntry *entry = ptr->data;
	if (entry->description) {
		strcpy(value, entry->description);
	}
	else {
		*value = '\0';
	}
}

static int rna_AssetEntry_description_length(struct PointerRNA *ptr)
{
	FileDirEntry *entry = ptr->data;
	return entry->description ? strlen(entry->description) : 0;
}

static void rna_AssetEntry_description_set(struct PointerRNA *ptr, const char *value)
{
	FileDirEntry *entry = ptr->data;
	MEM_SAFE_FREE(entry->description);
	if (value[0] != '\0') {
		entry->description = BLI_strdup(value);
	}
}

/* Entries Array. */
static PointerRNA rna_AssetList_active_entry_get(PointerRNA *ptr)
{
	FileDirEntryArr *arr = ptr->data;
	return rna_pointer_inherit_refine(ptr, &RNA_AssetEntry, arr->entries.first /* BLI_findlink(&arr->entries, 0) */);
}

static void rna_AssetList_active_entry_set(PointerRNA *ptr, PointerRNA value)
{
	FileDirEntryArr *arr = ptr->data;
	FileDirEntry *entry = value.data;

	BLI_remlink_safe(&arr->entries, entry);
	BLI_addhead(&arr->entries, entry);
}

static int rna_AssetList_active_entry_index_get(PointerRNA *UNUSED(ptr))
{
	return 0;
}

static FileDirEntry *rna_AssetList_entries_add(FileDirEntryArr *dirlist)
{
	FileDirEntry *entry = MEM_callocN(sizeof(*entry), __func__);

	BLI_addtail(&dirlist->entries, entry);

	return entry;
}

static void rna_AssetList_entries_remove(FileDirEntryArr *dirlist, ReportList *reports, PointerRNA *ptr)
{
	FileDirEntry *entry = ptr->data;

	if (!BLI_remlink_safe(&dirlist->entries, entry)) {
		BKE_report(reports, RPT_ERROR, "Trying to remove an entry from a list which does not contain it!");
		return;
	}

	BKE_filedir_entry_free(entry);
}

static void rna_AssetList_entries_clear(FileDirEntryArr *dirlist)
{
	BKE_filedir_entryarr_clear(dirlist);
}

/* AssetEngine API. */

static void rna_ae_report(AssetEngine *engine, int type, const char *msg)
{
	BKE_report(engine->reports, type, msg);
}

/* AssetEngine callbacks. */

static int rna_ae_status(AssetEngine *engine, const int id)
{
	extern FunctionRNA rna_AssetEngine_status_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	int ret_status;

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_status_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "job_id", &id);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "status_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_status = *(int *)ret;

	RNA_parameter_list_free(&list);

	return ret_status;
}

static float rna_ae_progress(AssetEngine *engine, const int job_id)
{
	extern FunctionRNA rna_AssetEngine_progress_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	float ret_progress;

	BLI_assert(job_id != AE_JOB_ID_INVALID);

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_progress_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "job_id", &job_id);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "progress_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_progress = *(float *)ret;

	RNA_parameter_list_free(&list);

	return ret_progress;
}

static void rna_ae_kill(AssetEngine *engine, const int job_id)
{
	extern FunctionRNA rna_AssetEngine_kill_func;
	PointerRNA ptr;
	ParameterList list;
	FunctionRNA *func;

	BLI_assert(job_id != AE_JOB_ID_INVALID);

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_kill_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "job_id", &job_id);
	engine->type->ext.call(NULL, &ptr, func, &list);

	RNA_parameter_list_free(&list);
}

static int rna_ae_list_dir(AssetEngine *engine, const int job_id, FileDirEntryArr *entries_r)
{
	extern FunctionRNA rna_AssetEngine_list_dir_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	int ret_job_id;

	BLI_assert(job_id != AE_JOB_ID_INVALID);

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_list_dir_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "job_id", &job_id);
	RNA_parameter_set_lookup(&list, "entries", &entries_r);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "job_id_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_job_id = *(int *)ret;

	RNA_parameter_list_free(&list);

	return ret_job_id;
}

static int rna_ae_update_check(AssetEngine *engine, const int job_id, AssetUUIDList *uuids)
{
	extern FunctionRNA rna_AssetEngine_update_check_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	int ret_job_id;

	BLI_assert(job_id != AE_JOB_ID_INVALID);

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_update_check_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "job_id", &job_id);
	RNA_parameter_set_lookup(&list, "uuids", &uuids);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "job_id_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_job_id = *(int *)ret;

	RNA_parameter_list_free(&list);

	return ret_job_id;
}

static int rna_ae_ensure_uuids(AssetEngine *engine, const int job_id, AssetUUIDList *uuids)
{
	extern FunctionRNA rna_AssetEngine_ensure_uuids_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	int ret_job_id;

	BLI_assert(job_id != AE_JOB_ID_INVALID);

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_ensure_uuids_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "job_id", &job_id);
	RNA_parameter_set_lookup(&list, "uuids", &uuids);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "job_id_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_job_id = *(int *)ret;

	RNA_parameter_list_free(&list);

	return ret_job_id;
}

static bool rna_ae_load_pre(AssetEngine *engine, AssetUUIDList *uuids, struct FileDirEntryArr *entries_r)
{
	extern FunctionRNA rna_AssetEngine_load_pre_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	bool ret_success;

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_load_pre_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "uuids", &uuids);
	RNA_parameter_set_lookup(&list, "entries", &entries_r);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "success_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_success = ((*(int *)ret) != 0);

	RNA_parameter_list_free(&list);

	return ret_success;
}

static void rna_ae_check_dir(AssetEngine *engine, char *r_dir)
{
	extern FunctionRNA rna_AssetEngine_check_dir_func;
	PointerRNA ptr;
	ParameterList list;
	FunctionRNA *func;

	/* XXX Hacking around bpyrna incapacity to handle strings as return values... To be fixed... some day... */
	FileDirEntryArr entries = {0};
	FileDirEntryArr *entries_p = &entries;
	BLI_strncpy(entries.root, r_dir, FILE_MAX);

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_check_dir_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "entries", &entries_p);
	engine->type->ext.call(NULL, &ptr, func, &list);

	BLI_strncpy(r_dir, entries.root, FILE_MAX);

	RNA_parameter_list_free(&list);
}

static bool rna_ae_sort_filter(
        AssetEngine *engine, const bool use_sort, const bool use_filter,
        FileSelectParams *params, FileDirEntryArr *entries_r)
{
	extern FunctionRNA rna_AssetEngine_sort_filter_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	bool ret_changed;
	/* **Never** pass address of a bool for a bool prop! will be read as an int... */
	const int use_sort_i = (int)use_sort;
	const int use_filter_i = (int)use_filter;

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_sort_filter_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "use_sort", &use_sort_i);
	RNA_parameter_set_lookup(&list, "use_filter", &use_filter_i);
	RNA_parameter_set_lookup(&list, "params", &params);
	RNA_parameter_set_lookup(&list, "entries", &entries_r);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "changed_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_changed = ((*(int *)ret) != 0);

	RNA_parameter_list_free(&list);

	return ret_changed;
}

static bool rna_ae_entries_block_get(
        AssetEngine *engine, const int start_index, const int end_index, FileDirEntryArr *entries_r)
{
	extern FunctionRNA rna_AssetEngine_entries_block_get_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	bool ret_success;

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_entries_block_get_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "start_index", &start_index);
	RNA_parameter_set_lookup(&list, "end_index", &end_index);
	RNA_parameter_set_lookup(&list, "entries", &entries_r);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "success_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_success = ((*(int *)ret) != 0);

	RNA_parameter_list_free(&list);

	return ret_success;
}

static bool rna_ae_entries_uuid_get(
        AssetEngine *engine, AssetUUIDList *uuids, FileDirEntryArr *entries_r)
{
	extern FunctionRNA rna_AssetEngine_entries_uuid_get_func;
	PointerRNA ptr;
	PropertyRNA *parm;
	ParameterList list;
	FunctionRNA *func;

	void *ret;
	bool ret_success;

	RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
	func = &rna_AssetEngine_entries_uuid_get_func;

	RNA_parameter_list_create(&list, &ptr, func);
	RNA_parameter_set_lookup(&list, "uuids", &uuids);
	RNA_parameter_set_lookup(&list, "entries", &entries_r);
	engine->type->ext.call(NULL, &ptr, func, &list);

	parm = RNA_function_find_parameter(NULL, func, "success_return");
	RNA_parameter_get(&list, parm, &ret);
	ret_success = ((*(int *)ret) != 0);

	RNA_parameter_list_free(&list);

	return ret_success;
}


/* AssetEngine registration */

static void rna_AssetEngine_unregister(Main *UNUSED(bmain), StructRNA *type)
{
	AssetEngineType *aet = RNA_struct_blender_type_get(type);

	if (!aet) {
		return;
	}
	
	RNA_struct_free_extension(type, &aet->ext);
	BLI_freelinkN(&asset_engines, aet);
	RNA_struct_free(&BLENDER_RNA, type);
}

static StructRNA *rna_AssetEngine_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
                                           StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
	AssetEngineType *aet, dummyaet = {NULL};
	AssetEngine dummyengine = {NULL};
	PointerRNA dummyptr;
	int have_function[11];

	/* setup dummy engine & engine type to store static properties in */
	dummyengine.type = &dummyaet;
	RNA_pointer_create(NULL, &RNA_AssetEngine, &dummyengine, &dummyptr);

	/* validate the python class */
	if (validate(&dummyptr, data, have_function) != 0) {
		return NULL;
	}

	if (strlen(identifier) >= sizeof(dummyaet.idname)) {
		BKE_reportf(reports, RPT_ERROR, "Registering asset engine class: '%s' is too long, maximum length is %d",
		            identifier, (int)sizeof(dummyaet.idname));
		return NULL;
	}

	/* Check if we have registered this engine type before, and remove it. */
	aet = BLI_rfindstring(&asset_engines, dummyaet.idname, offsetof(AssetEngineType, idname));
	if (aet && aet->ext.srna) {
		rna_AssetEngine_unregister(bmain, aet->ext.srna);
	}
	
	/* Create a new engine type. */
	aet = MEM_callocN(sizeof(AssetEngineType), __func__);
	memcpy(aet, &dummyaet, sizeof(*aet));

	aet->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, aet->idname, &RNA_AssetEngine);
	aet->ext.data = data;
	aet->ext.call = call;
	aet->ext.free = free;
	RNA_struct_blender_type_set(aet->ext.srna, aet);

	aet->status = (have_function[0]) ? rna_ae_status : NULL;
	aet->progress = (have_function[1]) ? rna_ae_progress : NULL;
	aet->kill = (have_function[2]) ? rna_ae_kill : NULL;

	aet->list_dir = (have_function[3]) ? rna_ae_list_dir : NULL;

	aet->update_check = (have_function[4]) ? rna_ae_update_check : NULL;

	aet->ensure_uuids = (have_function[5]) ? rna_ae_ensure_uuids : NULL;

	aet->load_pre = (have_function[6]) ? rna_ae_load_pre : NULL;

	aet->check_dir = (have_function[7]) ? rna_ae_check_dir : NULL;

	aet->sort_filter = (have_function[8]) ? rna_ae_sort_filter : NULL;
	aet->entries_block_get = (have_function[9]) ? rna_ae_entries_block_get : NULL;
	aet->entries_uuid_get = (have_function[10]) ? rna_ae_entries_uuid_get : NULL;

	BLI_addtail(&asset_engines, aet);

	return aet->ext.srna;
}

static void **rna_AssetEngine_instance(PointerRNA *ptr)
{
	AssetEngine *engine = ptr->data;
	return &engine->py_instance;
}

static StructRNA *rna_AssetEngine_refine(PointerRNA *ptr)
{
	AssetEngine *engine = ptr->data;
	return (engine->type && engine->type->ext.srna) ? engine->type->ext.srna : &RNA_AssetEngine;
}

static IDProperty *rna_AssetEngine_idprops(PointerRNA *ptr, bool create)
{
	AssetEngine *ae = (AssetEngine *)ptr->data;
	if (create && !ae->properties) {
		IDPropertyTemplate val = {0};
		ae->properties = IDP_New(IDP_GROUP, &val, "RNA_AssetEngine IDproperties group");
	}

	return ae->properties;
}

static int rna_AssetEngine_const_job_id_invalid_get(PointerRNA *UNUSED(ptr))
{
	return AE_JOB_ID_INVALID;
}

static int rna_AssetEngine_const_job_id_unset_get(PointerRNA *UNUSED(ptr))
{
	return AE_JOB_ID_UNSET;
}

static int rna_AssetEngine_is_dirty_sorting_get(PointerRNA *ptr)
{
	AssetEngine *ae = ptr->data;
	return (ae->flag & AE_DIRTY_SORTING) != 0;
}

static void rna_AssetEngine_is_dirty_sorting_set(PointerRNA *ptr, int val)
{
	AssetEngine *ae = ptr->data;
	if (val) {
		ae->flag |= AE_DIRTY_SORTING;
	}
	else {
		ae->flag &= ~AE_DIRTY_SORTING;
	}
}

static int rna_AssetEngine_is_dirty_filtering_get(PointerRNA *ptr)
{
	AssetEngine *ae = ptr->data;
	return (ae->flag & AE_DIRTY_FILTER) != 0;
}

static void rna_AssetEngine_is_dirty_filtering_set(PointerRNA *ptr, int val)
{
	AssetEngine *ae = ptr->data;
	if (val) {
		ae->flag |= AE_DIRTY_FILTER;
	}
	else {
		ae->flag &= ~AE_DIRTY_FILTER;
	}
}

#else /* RNA_RUNTIME */

/* Much lighter version of asset/variant/revision identifier. */
static void rna_def_asset_uuid(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	int null_uuid[4] = {0};

	srna = RNA_def_struct(brna, "AssetUUID", NULL);
	RNA_def_struct_sdna(srna, "AssetUUID");
	RNA_def_struct_ui_text(srna, "Asset UUID", "A unique identifier of an asset (asset engine dependent!)");

	RNA_def_int_vector(srna, "uuid_asset", 4, null_uuid, INT_MIN, INT_MAX,
	                   "Asset UUID", "Unique identifier of this asset", INT_MIN, INT_MAX);

	RNA_def_int_vector(srna, "uuid_variant", 4, null_uuid, INT_MIN, INT_MAX,
	                   "Variant UUID", "Unique identifier of this asset's variant", INT_MIN, INT_MAX);

	RNA_def_int_vector(srna, "uuid_revision", 4, null_uuid, INT_MIN, INT_MAX,
	                   "Revision UUID", "Unique identifier of this asset's revision", INT_MIN, INT_MAX);

	prop = RNA_def_boolean(srna, "is_unknown_engine", false, "Unknown Asset Engine",
	                       "This AssetUUID is referencing an unknown asset engine");
	RNA_def_property_boolean_sdna(prop, NULL, "tag", UUID_TAG_ENGINE_MISSING);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);

	prop = RNA_def_boolean(srna, "is_asset_missing", false, "Missing Asset",
	                       "This AssetUUID is no more known by its asset engine");
	RNA_def_property_boolean_sdna(prop, NULL, "tag", UUID_TAG_ASSET_MISSING);

	prop = RNA_def_boolean(srna, "use_asset_reload", false, "Reload Asset",
	                       "The data matching this AssetUUID should be reloaded");
	RNA_def_property_boolean_sdna(prop, NULL, "tag", UUID_TAG_ASSET_RELOAD);
}

static void rna_def_asset_uuid_list(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "AssetUUIDList", NULL);
	RNA_def_struct_sdna(srna, "AssetUUIDList");
	RNA_def_struct_ui_text(srna, "Asset UUIDs List", "Collection of assets uuids");

	prop = RNA_def_property(srna, "uuids", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "uuids", "nbr_uuids");
	RNA_def_property_struct_type(prop, "AssetUUID");
	RNA_def_property_ui_text(prop, "UUIDs", "Collection of asset UUIDs");

	prop = RNA_def_int(srna, "asset_engine_version", 0, 0, INT_MAX, "Asset Engine Version",
	                   "Asset engine version those uuids were generated from", 0, INT_MAX);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);

	rna_def_asset_uuid(brna);
}

static void rna_def_asset_revision(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
//	FunctionRNA *func;

	int null_uuid[4] = {0};

	srna = RNA_def_struct(brna, "AssetRevision", NULL);
	RNA_def_struct_sdna(srna, "FileDirEntryRevision");
	RNA_def_struct_ui_text(srna, "Asset Entry Revision", "A revision of a single asset item");
//	RNA_def_struct_ui_icon(srna, ICON_NONE);  /* XXX TODO */

	prop = RNA_def_int_vector(srna, "uuid", 4, null_uuid, INT_MIN, INT_MAX, "Revision UUID",
	                          "Unique identifier of this revision (actual content depends on asset engine)",
	                          INT_MIN, INT_MAX);

	prop = RNA_def_int(srna, "size", 0, -1, INT_MAX, "Size",
	                   "Size (in bytes, special value '-1' means 'no size')", -1, INT_MAX);
	RNA_def_property_int_funcs(prop, "rna_AssetRevision_size_get", "rna_AssetRevision_size_set", NULL);

	prop = RNA_def_int(srna, "timestamp", 0, 0, INT_MAX, "Timestamp", "In seconds since the epoch", 0, INT_MAX);
	RNA_def_property_int_funcs(prop, "rna_AssetRevision_timestamp_get", "rna_AssetRevision_timestamp_set", NULL);
}

/* assetvariant.revisions */
static void rna_def_asset_revisions(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm;
	PropertyRNA *prop;

	RNA_def_property_srna(cprop, "AssetRevisions");
	srna = RNA_def_struct(brna, "AssetRevisions", NULL);
	RNA_def_struct_sdna(srna, "FileDirEntryVariant");
	RNA_def_struct_ui_text(srna, "Asset Entry Revisions", "Collection of asset entry's revisions");

	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "AssetRevision");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_pointer_funcs(prop, "rna_AssetVariant_active_revision_get",
	                               "rna_AssetVariant_active_revision_set", NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Revision", "Active (selected) revision of the asset");

	prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "act_revision");
	RNA_def_property_ui_text(prop, "Active Index", "Index of asset's revision curently active (selected)");

	/* Add Revision */
	func = RNA_def_function(srna, "add", "rna_AssetVariant_revisions_add");
	RNA_def_function_ui_description(func, "Add a new revision to the entry's variant");
//	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	/* return arg */
	parm = RNA_def_pointer(func, "revision", "AssetRevision", "New Revision", "New asset entry variant revision");
	RNA_def_function_return(func, parm);
}

static void rna_def_asset_variant(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
//	FunctionRNA *func;

	int null_uuid[4] = {0};

	srna = RNA_def_struct(brna, "AssetVariant", NULL);
	RNA_def_struct_sdna(srna, "FileDirEntryVariant");
	RNA_def_struct_ui_text(srna, "Asset Entry Variant",
	                       "A variant of a single asset item (e.g. high-poly, low-poly, etc.)");
//	RNA_def_struct_ui_icon(srna, ICON_NONE);  /* XXX TODO */

	prop = RNA_def_int_vector(srna, "uuid", 4, null_uuid, INT_MIN, INT_MAX, "Variant UUID",
	                          "Unique identifier of this revision (actual content depends on asset engine)",
	                          INT_MIN, INT_MAX);

	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_string_funcs(prop, "rna_AssetVariant_name_get", "rna_AssetVariant_name_length",
	                              "rna_AssetVariant_name_set");
	RNA_def_property_ui_text(prop, "Name", "");

	prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_string_funcs(prop, "rna_AssetVariant_description_get", "rna_AssetVariant_description_length",
	                              "rna_AssetVariant_description_set");
	RNA_def_property_ui_text(prop, "Description", "");

	prop = RNA_def_property(srna, "revisions", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "AssetRevision");
	RNA_def_property_ui_text(prop, "Revisions", "Collection of asset variant's revisions");
	rna_def_asset_revision(brna);
	rna_def_asset_revisions(brna, prop);
}

/* assetentry.variants */
static void rna_def_asset_variants(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm;
	PropertyRNA *prop;

	RNA_def_property_srna(cprop, "AssetVariants");
	srna = RNA_def_struct(brna, "AssetVariants", NULL);
	RNA_def_struct_sdna(srna, "FileDirEntry");
	RNA_def_struct_ui_text(srna, "Asset Entry Variants", "Collection of asset entry's variants");

	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "AssetVariant");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_pointer_funcs(prop, "rna_AssetEntry_active_variant_get",
	                               "rna_AssetEntry_active_variant_set", NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Variant", "Active (selected) variant of the asset");

	prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "act_variant");
	RNA_def_property_ui_text(prop, "Active Index", "Index of asset's variant curently active (selected)");

	/* Add Variant */
	func = RNA_def_function(srna, "add", "rna_AssetEntry_variants_add");
	RNA_def_function_ui_description(func, "Add a new variant to the entry");
//	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	/* return arg */
	parm = RNA_def_pointer(func, "variant", "AssetVariant", "New Variant", "New asset entry variant");
	RNA_def_function_return(func, parm);
}

static void rna_def_asset_entry(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
//	FunctionRNA *func;

	static EnumPropertyItem asset_revision_types[] = {
	    {FILE_TYPE_BLENDER, "BLENDER", 0, "Blender File", ""},
//	    {FILE_TYPE_BLENDER_BACKUP, "", 0, "", ""},
	    {FILE_TYPE_IMAGE, "IMAGE", 0, "Image", ""},
	    {FILE_TYPE_MOVIE, "MOVIE", 0, "Movie", ""},
	    {FILE_TYPE_PYSCRIPT, "PYSCRIPT", 0, "Python Script", ""},
	    {FILE_TYPE_FTFONT, "FONT", 0, "Font", ""},
	    {FILE_TYPE_SOUND, "SOUND", 0, "Sound", ""},
	    {FILE_TYPE_TEXT, "TEXT", 0, "Text", ""},
//	    {FILE_TYPE_MOVIE_ICON, "", 0, "", ""},
//	    {FILE_TYPE_FOLDER, "", 0, "", ""},
//	    {FILE_TYPE_BTX, "", 0, "", ""},
//	    {FILE_TYPE_COLLADA, "", 0, "", ""},
//	    {FILE_TYPE_OPERATOR, "", 0, "", ""},
//	    {FILE_TYPE_APPLICATIONBUNDLE, "", 0, "", ""},
	    {FILE_TYPE_DIR, "DIR", 0, "Directory", "An entry that can be used as 'root' path too"},
	    {FILE_TYPE_BLENDERLIB, "BLENLIB", 0, "Blender Library", "An entry that is part of a .blend file"},
	    {0, NULL, 0, NULL, NULL}
	};

	int null_uuid[4] = {0};

	srna = RNA_def_struct(brna, "AssetEntry", NULL);
	RNA_def_struct_sdna(srna, "FileDirEntry");
	RNA_def_struct_ui_text(srna, "Asset Entry", "A single asset item (quite similar to a file path)");
//	RNA_def_struct_ui_icon(srna, ICON_NONE);  /* XXX TODO */

	prop = RNA_def_int_vector(srna, "uuid", 4, null_uuid, INT_MIN, INT_MAX, "Variant UUID",
	                          "Unique identifier of this entry (actual content depends on asset engine)",
	                          INT_MIN, INT_MAX);

	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_string_funcs(prop, "rna_AssetEntry_name_get", "rna_AssetEntry_name_length",
	                              "rna_AssetEntry_name_set");
	RNA_def_property_ui_text(prop, "Name", "");

	prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_string_funcs(prop, "rna_AssetEntry_description_get", "rna_AssetEntry_description_length",
	                              "rna_AssetEntry_description_set");
	RNA_def_property_ui_text(prop, "Description", "");

	prop = RNA_def_property(srna, "relpath", PROP_STRING, PROP_NONE);
	RNA_def_property_string_funcs(prop, "rna_AssetEntry_relpath_get", "rna_AssetEntry_relpath_length",
	                              "rna_AssetEntry_relpath_set");
	RNA_def_property_ui_text(prop, "Relative Path", "Relative to AssetList's root_path");

	prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
	RNA_def_property_flag(prop, PROP_ENUM_FLAG);
	RNA_def_property_enum_bitflag_sdna(prop, NULL, "typeflag");
	RNA_def_property_enum_items(prop, asset_revision_types);

	prop = RNA_def_property(srna, "blender_type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "blentype");
	RNA_def_property_enum_items(prop, rna_enum_id_type_items);

	prop = RNA_def_property(srna, "variants", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "AssetVariant");
	RNA_def_property_ui_text(prop, "Variants", "Collection of asset variants");
	rna_def_asset_variant(brna);
	rna_def_asset_variants(brna, prop);

	/* TODO: image (i.e. preview)? */

	/* TODO tags, status */
}

/* assetlist.entries */
static void rna_def_asset_entries(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm, *prop;

	RNA_def_property_srna(cprop, "AssetEntries");
	srna = RNA_def_struct(brna, "AssetEntries", NULL);
	RNA_def_struct_sdna(srna, "FileDirEntryArr");
	RNA_def_struct_ui_text(srna, "Asset List entries", "Collection of asset entries");

	/* Currently, 'active' entry (i.e. the one passed to single-file arg of operators) is always the
	 * first of the list... */
	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "AssetEntry");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_pointer_funcs(prop, "rna_AssetList_active_entry_get",
	                               "rna_AssetList_active_entry_set", NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Entry", "Active (selected) entry of the list");

	prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_AssetList_active_entry_index_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Index", "Index of entry curently active (selected)");

	/* Add Entry */
	func = RNA_def_function(srna, "add", "rna_AssetList_entries_add");
	RNA_def_function_ui_description(func, "Add a new asset entry to the list");
	/* return arg */
	parm = RNA_def_pointer(func, "entry", "AssetEntry", "New Entry", "New asset entry");
	RNA_def_function_return(func, parm);

	/* Remove Entry */
	func = RNA_def_function(srna, "remove", "rna_AssetList_entries_remove");
	RNA_def_function_ui_description(func, "Remove the given entry from the list (entry is freeded)");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	parm = RNA_def_pointer(func, "entry", "AssetEntry", "Entry", "");
	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
	RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);

	/* Remove All Entries */
	func = RNA_def_function(srna, "clear", "rna_AssetList_entries_clear");
	RNA_def_function_ui_description(func, "Remove all entries from the list");
}

static void rna_def_asset_list(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
//	FunctionRNA *func;

	srna = RNA_def_struct(brna, "AssetList", NULL);
	RNA_def_struct_sdna(srna, "FileDirEntryArr");
	RNA_def_struct_ui_text(srna, "Asset List", "List of assets (quite similar to a file list)");
//	RNA_def_struct_ui_icon(srna, ICON_NONE);  /* XXX TODO */

	prop = RNA_def_property(srna, "entries", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "AssetEntry");
	RNA_def_property_ui_text(prop, "Entries", "Collection of asset entries");
	rna_def_asset_entry(brna);
	rna_def_asset_entries(brna, prop);

	prop = RNA_def_int(srna, "nbr_entries", 0, 0, INT_MAX, "Entries Number",
	                   "Total number of available entries/assets, *not the length of 'entries'!*", 0, INT_MAX);
	RNA_def_property_int_sdna(prop, NULL, "nbr_entries");

	prop = RNA_def_int(srna, "nbr_entries_filtered", 0, 0, INT_MAX, "Filtered Entries Number",
	                   "Total number of visible entries/assets, *not the length of 'entries'!*", 0, INT_MAX);
	RNA_def_property_int_sdna(prop, NULL, "nbr_entries_filtered");

	prop = RNA_def_property(srna, "root_path", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "root");
	RNA_def_property_ui_text(prop, "Root Path", "Root directory from which all asset entries come from");
}

static void rna_def_asset_engine(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop, *parm;
	FunctionRNA *func;

	static EnumPropertyItem asset_engine_status_types[] = {
	    {AE_STATUS_VALID, "VALID", 0, "Valid", ""},
	    {AE_STATUS_RUNNING, "RUNNING", 0, "Running", ""},
	    {0, NULL, 0, NULL, NULL}
	};

	srna = RNA_def_struct(brna, "AssetEngine", NULL);
	RNA_def_struct_sdna(srna, "AssetEngine");
	RNA_def_struct_ui_text(srna, "Asset Engine", "An assets manager");
	RNA_def_struct_refine_func(srna, "rna_AssetEngine_refine");
	RNA_def_struct_register_funcs(srna, "rna_AssetEngine_register", "rna_AssetEngine_unregister",
	                              "rna_AssetEngine_instance");
	RNA_def_struct_idprops_func(srna, "rna_AssetEngine_idprops");

	/* Constants (sigh). */
	prop = RNA_def_int(srna, "job_id_invalid", AE_JOB_ID_INVALID, AE_JOB_ID_INVALID, AE_JOB_ID_INVALID + 1, "",
	                   "'Invalid' constant for job id, return this when a job callback did not start a job",
	                   AE_JOB_ID_INVALID, AE_JOB_ID_INVALID + 1);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_AssetEngine_const_job_id_invalid_get", NULL, NULL);

	prop = RNA_def_int(srna, "job_id_unset", AE_JOB_ID_UNSET, AE_JOB_ID_UNSET, AE_JOB_ID_UNSET + 1, "",
	                   "'Unset' constant for job id, passed when blender wants to create a new job e.g.",
	                   AE_JOB_ID_UNSET, AE_JOB_ID_UNSET + 1);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_AssetEngine_const_job_id_unset_get", NULL, NULL);

	/* AssetEngine state. */
	prop = RNA_def_property(srna, "is_dirty_sorting", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_AssetEngine_is_dirty_sorting_get",
	                               "rna_AssetEngine_is_dirty_sorting_set");
	RNA_def_property_ui_text(prop, "Dirty Sorting", "FileBrowser shall call AE's sorting function on next draw");
	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);

	prop = RNA_def_property(srna, "is_dirty_filtering", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_AssetEngine_is_dirty_filtering_get",
	                               "rna_AssetEngine_is_dirty_filtering_set");
	RNA_def_property_ui_text(prop, "Dirty Filtering", "FileBrowser shall call AE's filtering function on next draw");
	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);

	/* Utilities, not for registering. */
	func = RNA_def_function(srna, "report", "rna_ae_report");
	RNA_def_function_ui_description(func, "Generate a report (error, info, warning, etc.)");
	parm = RNA_def_enum_flag(func, "type", rna_enum_wm_report_items, 0, "", "");
	RNA_def_property_flag(parm, PROP_REQUIRED);
	parm = RNA_def_string(func, "message", NULL, 0, "", "");
	RNA_def_property_flag(parm, PROP_REQUIRED);

	/* API */

	/* Status callback */
	func = RNA_def_function(srna, "status", NULL);
	RNA_def_function_ui_description(func, "Get status of whole engine, or a given job");
	RNA_def_function_flag(func, FUNC_REGISTER);
	RNA_def_int(func, "job_id", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	            "Job ID (JOB_ID_UNSET to get engine status itself)", AE_JOB_ID_INVALID, INT_MAX);
	parm = RNA_def_enum(func, "status_return", asset_engine_status_types, 0, "", "Status of given job or whole engine");
	RNA_def_property_flag(parm, PROP_ENUM_FLAG);
	RNA_def_function_output(func, parm);

	/* Progress callback */
	func = RNA_def_function(srna, "progress", NULL);
	RNA_def_function_ui_description(func, "Get progress of a given job, or all running ones (between 0.0 and 1.0)");
	RNA_def_function_flag(func, FUNC_REGISTER);
	RNA_def_int(func, "job_id", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	            "Job ID (JOB_ID_UNSET to get average progress of all running jobs)", AE_JOB_ID_INVALID, INT_MAX);
	parm = RNA_def_float(func, "progress_return", 0.0f, 0.0f, 1.0f, "", "Progress", 0.0f, 1.0f);
	RNA_def_function_output(func, parm);

	/* Kill job callback */
	func = RNA_def_function(srna, "kill", NULL);
	RNA_def_function_ui_description(func, "Unconditionnaly stop a given job, or all running ones");
	RNA_def_function_flag(func, FUNC_REGISTER);
	RNA_def_int(func, "job_id", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	            "Job ID (JOB_ID_UNSET to kill all)", AE_JOB_ID_INVALID, INT_MAX);

	/* Main listing callback */
	func = RNA_def_function(srna, "list_dir", NULL);
	RNA_def_function_ui_description(func, "Start/update the list of available entries (assets)");
	RNA_def_function_flag(func, FUNC_REGISTER | FUNC_ALLOW_WRITE);
	RNA_def_int(func, "job_id", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	            "Job ID (JOB_ID_UNSET to start a new one)", AE_JOB_ID_INVALID, INT_MAX);
	RNA_def_pointer(func, "entries", "AssetList", "", "List of asset entries proposed to user by the asset engine");
	parm = RNA_def_int(func, "job_id_return", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	                   "Job ID (if JOB_ID_INVALID, job is assumed already finished)", AE_JOB_ID_INVALID, INT_MAX);
	RNA_def_function_output(func, parm);

	/* Update callback */
	func = RNA_def_function(srna, "update_check", NULL);
	RNA_def_function_ui_description(func, "Check for already loaded asset status (is updated, still valid, etc.)");
	RNA_def_function_flag(func, FUNC_REGISTER | FUNC_ALLOW_WRITE);
	RNA_def_int(func, "job_id", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	            "Job ID (JOB_ID_UNSET to start a new one)", AE_JOB_ID_INVALID, INT_MAX);
	RNA_def_pointer(func, "uuids", "AssetUUIDList", "", "Identifiers of assets to check");
	parm = RNA_def_int(func, "job_id_return", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	                   "Job ID (if JOB_ID_INVALID, job is assumed already finished)", AE_JOB_ID_INVALID, INT_MAX);
	RNA_def_function_output(func, parm);

	/* Ensure (pre-load) callback */
	func = RNA_def_function(srna, "ensure_uuids", NULL);
	RNA_def_function_ui_description(func, "Ensure given UUIDs are really available "
	                                      "(download or generate to local cahe, etc.)");
	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
	RNA_def_int(func, "job_id", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	            "Job ID (JOB_ID_UNSET to start a new one)", AE_JOB_ID_INVALID, INT_MAX);
	RNA_def_pointer(func, "uuids", "AssetUUIDList", "", "Identifiers of assets to 'ensure'");
	parm = RNA_def_int(func, "job_id_return", AE_JOB_ID_UNSET, AE_JOB_ID_INVALID, INT_MAX, "",
	                   "Job ID (if JOB_ID_INVALID, job is assumed already finished)", AE_JOB_ID_INVALID, INT_MAX);
	RNA_def_function_output(func, parm);

	/* Pre-load callback */
	func = RNA_def_function(srna, "load_pre", NULL);
	RNA_def_function_ui_description(func, "Pre-process given assets identifiers to make them loadable by Blender");
	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
	RNA_def_pointer(func, "uuids", "AssetUUIDList", "", "Identifiers of assets to 'make real'");
	RNA_def_pointer(func, "entries", "AssetList", "", "List of actual, existing paths that Blender can load");
	parm = RNA_def_boolean(func, "success_return", false, "", "Success");
	RNA_def_function_output(func, parm);

	/* Dir-validating callback */
	func = RNA_def_function(srna, "check_dir", NULL);
	RNA_def_function_ui_description(func, "Check if given path is valid (as in, can be listed) for this engine");
	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
	RNA_def_pointer(func, "entries", "AssetList", "", "Fake List of asset entries (only use/modify its root_path!)");

	/* Sorting/filtering callback */
	func = RNA_def_function(srna, "sort_filter", NULL);
	RNA_def_function_ui_description(func, "Sort and/or filter the assets (on engine's side)");
	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
	RNA_def_boolean(func, "use_sort", 0, "", "Whether to (re-)sort assets");
	RNA_def_boolean(func, "use_filter", 0, "", "Whether to (re-)filter assets");
	parm = RNA_def_pointer(func, "params", "FileSelectParams", "",
	                       "Generic filtering/sorting parameters from FileBrowser");
	RNA_def_pointer(func, "entries", "AssetList", "", "List of asset entries proposed to user by the asset engine");
	parm = RNA_def_boolean(func, "changed_return", false, "", "Whether list of available entries was changed");
	RNA_def_function_output(func, parm);

	/* Block of entries by-index getter callback */
	func = RNA_def_function(srna, "entries_block_get", NULL);
	RNA_def_function_ui_description(func, "Get a block of entries/assets by its (sorted/filtered) start/end index");
	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
	RNA_def_int(func, "start_index", 0, 0, INT_MAX, "", "Index of first entry (asset) to get (included)", 0, INT_MAX);
	RNA_def_int(func, "end_index", 0, 0, INT_MAX, "", "Index of last entry (asset) to get (excluded)", 0, INT_MAX);
	RNA_def_pointer(func, "entries", "AssetList", "", "List of asset entries proposed to user by the asset engine");
	parm = RNA_def_boolean(func, "success_return", false, "", "Success");
	RNA_def_function_output(func, parm);

	/* Set of entries by-uuids getter callback */
	func = RNA_def_function(srna, "entries_uuid_get", NULL);
	RNA_def_function_ui_description(func, "Get a set of entries/assets by their uuids");
	RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
	RNA_def_pointer(func, "uuids", "AssetUUIDList", "", "Identifiers of assets");
	RNA_def_pointer(func, "entries", "AssetList", "", "List of asset entries matching given uuids");
	parm = RNA_def_boolean(func, "success_return", false, "", "Success");
	RNA_def_function_output(func, parm);

	RNA_define_verify_sdna(false);

	/* registration */

	prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "type->idname");
	RNA_def_property_flag(prop, PROP_REGISTER);

	prop = RNA_def_property(srna, "bl_version", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "type->version");
	RNA_def_property_flag(prop, PROP_REGISTER);

	prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "type->name");
	RNA_def_property_flag(prop, PROP_REGISTER);

	RNA_define_verify_sdna(true);
}

void RNA_def_asset(BlenderRNA *brna)
{
	rna_def_asset_engine(brna);
	rna_def_asset_uuid_list(brna);
	rna_def_asset_list(brna);
}

#endif /* RNA_RUNTIME */