1 krisbash 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 krisbash 1.1 **==============================================================================
23 */
24
25 #ifndef _unsubscribe_h
26 #define _unsubscribe_h
27
28 #include <common.h>
29 #include <pal/lock.h>
30 #include <pal/thread.h>
31 #include "SubscriptionContext.h"
32 #include "provmgr.h"
33
34 BEGIN_EXTERNC
35
36 typedef struct _RequestItem RequestItem;
37 typedef struct _RequestList RequestList;
38 typedef struct _RequestHandler RequestHandler;
39
40 typedef enum _RequestType
41 {
42 REQUEST_UNSUBSCRIBE = 1,
43 krisbash 1.1 REQUEST_SUBSCRIBE = 2
44 }
45 RequestType;
46
47 struct _RequestItem
48 {
49 struct _RequestItem* next;
50 RequestType type;
51 };
52
53 typedef struct _UnsubscribeProviderItem
54 {
55 RequestItem base;
56 SubscriptionContext* ctx;
57 MI_Boolean invokeRequest;
58 MI_Result finalResult;
59 }
60 UnsubscribeProviderItem;
61
62 typedef struct _SubscribeProviderItem
63 {
64 krisbash 1.1 RequestItem base;
65 Provider* provider;
66 SubscribeReq* msg;
67 SubscriptionContext* subscrContext;
68 }
69 SubscribeProviderItem;
70
71 struct _RequestList
72 {
73 // Linked list of pending unsubscribe requests
74 struct _RequestItem* head;
75 struct _RequestItem* tail;
76
77 // Protect the linked list
78 ReadWriteLock lock;
79 };
80
81 struct _RequestHandler
82 {
83 Lock lock; // thread safely create unsubscribe thread
84 volatile ptrdiff_t running; // indication the thread is running (1) or not (0)
85 krisbash 1.1 Thread thread; // the unsubscribe thread
86 volatile ptrdiff_t joined; // indication the thread is joined by other thread (1) or not (0)
87 RequestList list; // pending unsubscribe requests
88 };
89
90 extern RequestHandler g_requesthandler;
91
92 void RequestList_Init(_Out_ RequestList* list);
93
94 void RequestHandler_Init(_Out_ RequestHandler* handler);
95 void RequestHandler_Finalize(_Inout_ RequestHandler* handler);
96
97 //
98 // Queue the unsubscribe request and spawn a new thread to
99 // perform the unsubscribe operation if not created yet
100 //
101 MI_Result Schedule_UnsubscribeProvider(
102 _In_ SubscriptionContext* ctx,
103 _In_ MI_Boolean invokeRequest,
104 _In_ MI_Result finalResult);
105
106 krisbash 1.1 //
107 // Queue sending final result request and spawn a new thread to
108 // perform the unsubscribe operation if not created yet
109 //
110 MI_Result Schedule_SendFinalResult(
111 _In_ SubscriptionContext* ctx,
112 _In_ MI_Result finalResult);
113
114 //
115 // Queue subscribe request and spawn a new thread to
116 // perform the unsubscribe operation if not created yet
117 //
118 MI_Result Schedule_SubscribeRequest(
119 _In_ Provider* provider,
120 _In_ SubscribeReq* msg,
121 _In_ SubscriptionContext* subscrContext );
122
123 END_EXTERNC
124
125 #endif /* _unsubscribe_h */
126
|