Modules/UDI - Attributes, PIO, CB allocation and channel_spawn
[tpg/acess2.git] / KernelLand / Modules / Interfaces / UDI / udi_lib / attr.c
1 /**
2  * Acess2 UDI Layer
3  * - By John Hodge (thePowersGang)
4  *
5  * udi_lib/attr.c
6  * - Instance Attribute Management
7  */
8 #include <acess.h>
9 #include <udi.h>
10 #include "../udi_internal.h"
11
12 // Notes:
13 // - Prefixes:
14 //  > '%': Private persistent
15 //  > '$': Private Volatile
16 //  > '':  Enumeration
17 //  > '^': Sibling group
18 //  > '@': parent-visible (persistent)
19
20 // === CODE ===
21 udi_instance_attr_type_t udi_instance_attr_get_internal(udi_cb_t *gcb, const char *attr_name, udi_ubit32_t child_ID, void *attr_value, udi_size_t attr_length, udi_size_t *actual_length)
22 {
23         // Get instance
24         tUDI_DriverInstance *inst = UDI_int_ChannelGetInstance(gcb, false, NULL);
25         
26         const tUDI_ChildBinding *bind = inst->ParentChildBinding;
27
28         // Search
29         switch(*attr_name)
30         {
31         // Private Persistent
32         case '%':
33                 // Read cached from tUDI_DriverModule
34                 // Write to permanent storage?
35                 break;
36         // Private Volatile
37         case '$':
38                 // Read from tUDI_DriverInstance
39                 break;
40         // Sibling group
41         case '^':
42                 // Read from parent's tUDI_DriverInstance
43                 break;
44         // Parent-Visible
45         case '@':
46                 // Read from tUDI_ChildBinding
47                 break;
48         // Enumeration
49         default:
50                 // Check associated tUDI_ChildBinding
51                 if( !inst->ParentChildBinding ) {
52                         return UDI_ATTR_NONE;
53                 }
54                 
55                 for( int i = 0; i < bind->nAttribs; i ++ )
56                 {
57                         const udi_instance_attr_list_t *at = &bind->Attribs[i];
58                         if( strcmp(at->attr_name, attr_name) == 0 )
59                         {
60                                 if( actual_length )
61                                         *actual_length = at->attr_length;
62                                 udi_size_t len = (at->attr_length < attr_length) ? at->attr_length : attr_length;
63                                 memcpy(attr_value, at->attr_value, len);
64                                 return at->attr_type;
65                         }
66                 }
67                 break;
68         }
69         // - Priv
70         // - enumeration attributes
71         // - set attributes
72         return UDI_ATTR_NONE;
73 }

UCC git Repository :: git.ucc.asn.au