Modules/UDI - NSR TX
[tpg/acess2.git] / KernelLand / Modules / Interfaces / UDI / udi_lib / core / imc.c
1 /**
2  * \file imc.c
3  * \author John Hodge (thePowersGang)
4  */
5 #define DEBUG   1
6 #include <udi.h>
7 #include <acess.h>
8 #include <udi_internal.h>
9 #include <udi_internal_ma.h>
10
11 // === EXPORTS ===
12 EXPORT(udi_channel_anchor);
13 EXPORT(udi_channel_spawn);
14 EXPORT(udi_channel_set_context);
15 EXPORT(udi_channel_op_abort);
16 EXPORT(udi_channel_close);
17 EXPORT(udi_channel_event_ind);
18 EXPORT(udi_channel_event_complete);
19
20 // === CODE ===
21 /**
22  */
23 void udi_channel_anchor(
24         udi_channel_anchor_call_t *callback, udi_cb_t *gcb,
25         udi_channel_t channel, udi_index_t ops_idx, void *channel_context
26         )
27 {
28         UNIMPLEMENTED();
29 }
30
31 /**
32  */
33 extern void udi_channel_spawn(
34         udi_channel_spawn_call_t *callback, udi_cb_t *gcb,
35         udi_channel_t channel, udi_index_t spawn_idx,
36         udi_index_t ops_idx, void *channel_context
37         )
38 {
39         LOG("gcb=%p,channel=%p,spawn_idx=%i,ops_idx=%i,channel_context=%p",
40                 gcb, channel, spawn_idx, ops_idx, channel_context);
41         
42         // Search existing channel for a matching spawn_idx
43         udi_channel_t ret = UDI_CreateChannel_Linked(channel, spawn_idx);
44
45         // Bind local end of channel to ops_idx (with channel_context)
46         if( ops_idx != 0 )
47         {
48                 udi_index_t     region_idx;
49                 tUDI_DriverInstance     *inst = UDI_int_ChannelGetInstance(gcb, false, &region_idx);
50                 UDI_BindChannel(ret, false, inst, ops_idx, region_idx, channel_context, false,0);
51         }
52         else
53         {
54                 // leave unbound
55         }
56
57         callback(gcb, ret);
58 }
59
60 /**
61  * 
62  */
63 void udi_channel_set_context(
64         udi_channel_t target_channel, void *channel_context
65         )
66 {
67         LOG("target_channel=%p,channel_context=%p", target_channel, channel_context);
68         UDI_int_ChannelSetContext(target_channel, channel_context);
69 }
70
71 void udi_channel_op_abort(
72         udi_channel_t target_channel, udi_cb_t *orig_cb
73         )
74 {
75         udi_channel_event_cb_t cb;
76         cb.gcb.channel = target_channel;
77         cb.event = UDI_CHANNEL_CLOSED;
78         cb.params.orig_cb = orig_cb;
79         udi_channel_event_ind(&cb);
80 }
81
82 void udi_channel_close(udi_channel_t channel)
83 {
84         Warning("%s Unimplemented", __func__);
85 }
86
87 void udi_channel_event_ind(udi_channel_event_cb_t *cb)
88 {
89         LOG("cb=%p{...}", cb);
90         const struct {
91                 udi_channel_event_ind_op_t *channel_event_ind_op;
92         } *ops = UDI_int_ChannelPrepForCall( UDI_GCB(cb), NULL, 0 );
93         if(!ops) {
94                 Log_Warning("UDI", "udi_channel_event_ind on wrong channel type");
95                 return ;
96         }
97
98         // UDI_int_MakeDeferredCb( UDI_GCB(cb), ops->channel_event_ind_op );
99
100         UDI_int_ChannelReleaseFromCall( UDI_GCB(cb) );  
101         ops->channel_event_ind_op(cb);
102 }
103
104 void udi_channel_event_complete(udi_channel_event_cb_t *cb, udi_status_t status)
105 {
106         LOG("cb=%p,status=%i", cb, status);
107         UDI_MA_TransitionState( UDI_GCB(cb)->initiator_context, UDI_MASTATE_PARENTBIND, UDI_MASTATE_ENUMCHILDREN );
108         udi_cb_free( UDI_GCB(cb) );
109 }

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