summaryrefslogtreecommitdiff
path: root/common_modules/module_manager/src/txm_module_manager_object_pointer_get_extended.c
blob: 1ddd987b3404e5758bb04dcb9235e611f34ed993 (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
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** ThreadX Component                                                     */
/**                                                                       */
/**   Module Manager                                                      */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define TX_SOURCE_CODE

#include "tx_api.h"
#include "tx_initialize.h"
#include "tx_thread.h"
#include "tx_timer.h"
#include "tx_queue.h"
#include "tx_event_flags.h"
#include "tx_semaphore.h"
#include "tx_mutex.h"
#include "tx_block_pool.h"
#include "tx_byte_pool.h"
#include "txm_module.h"
#include "txm_module_manager_util.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _txm_module_manager_object_pointer_get_extended     PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Scott Larson, Microsoft Corporation                                 */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function retrieves the object pointer of a particular type     */
/*    with a particular name. If the object is not found, an error is     */
/*    returned. Otherwise, if the object is found, the address of that    */
/*    object is placed in object_ptr.                                     */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    object_type                       Type of object, as follows:       */
/*                                                                        */
/*                                          TXM_BLOCK_POOL_OBJECT         */
/*                                          TXM_BYTE_POOL_OBJECT          */
/*                                          TXM_EVENT_FLAGS_OBJECT        */
/*                                          TXM_MUTEX_OBJECT              */
/*                                          TXM_QUEUE_OBJECT              */
/*                                          TXM_SEMAPHORE_OBJECT          */
/*                                          TXM_THREAD_OBJECT             */
/*                                          TXM_TIMER_OBJECT              */
/*    search_name                       Name to search for                */
/*    search_name_length                Length of the name excluding      */
/*                                        null-terminator                 */
/*    object_ptr                        Pointer to the object             */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    TX_SUCCESS                        Successful completion             */
/*    TX_PTR_ERROR                      Invalid name or object ptr        */
/*    TX_OPTION_ERROR                   Invalid option type               */
/*    TX_NO_INSTANCE                    Object not found                  */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _txm_module_manager_object_name_compare                             */
/*                                      String compare routine            */
/*    [_txm_module_manager_*_object_pointer_get]                          */
/*                                      Optional external component       */
/*                                        object pointer get              */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application code                                                    */
/*                                                                        */
/**************************************************************************/
UINT  _txm_module_manager_object_pointer_get_extended(UINT object_type, CHAR *search_name, UINT search_name_length, VOID **object_ptr)
{

TX_INTERRUPT_SAVE_AREA

TX_THREAD               *thread_ptr;
TX_TIMER                *timer_ptr;
TX_QUEUE                *queue_ptr;
TX_EVENT_FLAGS_GROUP    *events_ptr;
TX_SEMAPHORE            *semaphore_ptr;
TX_MUTEX                *mutex_ptr;
TX_BLOCK_POOL           *block_pool_ptr;
TX_BYTE_POOL            *byte_pool_ptr;
ULONG                   i;
UINT                    status;
TXM_MODULE_INSTANCE     *module_instance;


    /* Determine if the name or object pointer are NULL.  */
    if ((search_name == TX_NULL) || (object_ptr == TX_NULL))
    {

        /* Return error!  */
        return(TX_PTR_ERROR);
    }

    /* Default status to not found.  */
    status =  TX_NO_INSTANCE;

    /* Set the return value to NULL.  */
    *object_ptr =  TX_NULL;

    /* Disable interrupts.  */
    TX_DISABLE

    /* Temporarily disable preemption.  This will keep other threads from creating and deleting threads.  */
    _tx_thread_preempt_disable++;

    /* Restore interrupts.  */
    TX_RESTORE

    /* Process relative to the object type.  */
    switch(object_type)
    {

    /* Determine if a thread object is requested.  */
    case TXM_THREAD_OBJECT:
    {

        /* Loop to find the first matching thread.  */
        i = 0;
        thread_ptr =  _tx_thread_created_ptr;
        while (i < _tx_thread_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, thread_ptr -> tx_thread_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) thread_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next thread.  */
            thread_ptr =  thread_ptr -> tx_thread_created_next;
        }
        break;
    }

    /* Determine if a timer object is requested.  */
    case TXM_TIMER_OBJECT:
    {

        /* Loop to find the first matching timer.  */
        i = 0;
        timer_ptr =  _tx_timer_created_ptr;
        while (i < _tx_timer_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, timer_ptr -> tx_timer_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) timer_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next timer.  */
            timer_ptr =  timer_ptr -> tx_timer_created_next;
        }
        break;
    }

    /* Determine if a queue object is requested.  */
    case TXM_QUEUE_OBJECT:
    {

        /* Loop to find the first matching queue.  */
        i = 0;
        queue_ptr =  _tx_queue_created_ptr;
        while (i < _tx_queue_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, queue_ptr -> tx_queue_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) queue_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next queue.  */
            queue_ptr =  queue_ptr -> tx_queue_created_next;
        }
        break;
    }

    /* Determine if a event flags object is requested.  */
    case TXM_EVENT_FLAGS_OBJECT:
    {

        /* Loop to find the first matching event flags group.  */
        i = 0;
        events_ptr =  _tx_event_flags_created_ptr;
        while (i < _tx_event_flags_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, events_ptr -> tx_event_flags_group_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) events_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next event flags group.  */
            events_ptr =  events_ptr -> tx_event_flags_group_created_next;
        }
        break;
    }

    /* Determine if a semaphore object is requested.  */
    case TXM_SEMAPHORE_OBJECT:
    {

        /* Loop to find the first matching semaphore.  */
        i = 0;
        semaphore_ptr =  _tx_semaphore_created_ptr;
        while (i < _tx_semaphore_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, semaphore_ptr -> tx_semaphore_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) semaphore_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next semaphore.  */
            semaphore_ptr =  semaphore_ptr -> tx_semaphore_created_next;
        }
        break;
    }

    /* Determine if a mutex object is requested.  */
    case TXM_MUTEX_OBJECT:
    {

        /* Loop to find the first matching mutex.  */
        i = 0;
        mutex_ptr =  _tx_mutex_created_ptr;
        while (i < _tx_mutex_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, mutex_ptr -> tx_mutex_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) mutex_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next mutex.  */
            mutex_ptr =  mutex_ptr -> tx_mutex_created_next;
        }
        break;
    }

    /* Determine if a block pool object is requested.  */
    case TXM_BLOCK_POOL_OBJECT:
    {

        /* Get the module instance.  */
        module_instance =  _tx_thread_current_ptr -> tx_thread_module_instance_ptr;

        /* Is a module making this request?  */
        if (module_instance != TX_NULL)
        {

            /* Is memory protection enabled?  */
            if (module_instance -> txm_module_instance_property_flags & TXM_MODULE_MEMORY_PROTECTION)
            {

                /* Modules with memory protection can only access block pools they created.  */
                status =  TXM_MODULE_INVALID;
                break;
            }
        }

        /* Loop to find the first matching block pool.  */
        i = 0;
        block_pool_ptr =  _tx_block_pool_created_ptr;
        while (i < _tx_block_pool_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, block_pool_ptr -> tx_block_pool_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) block_pool_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next block pool.  */
            block_pool_ptr =  block_pool_ptr -> tx_block_pool_created_next;
        }
        break;
    }

    /* Determine if a byte pool object is requested.  */
    case TXM_BYTE_POOL_OBJECT:
    {

        /* Get the module instance.  */
        module_instance =  _tx_thread_current_ptr -> tx_thread_module_instance_ptr;

        /* Is a module making this request?  */
        if (module_instance != TX_NULL)
        {

            /* Is memory protection enabled?  */
            if (module_instance -> txm_module_instance_property_flags & TXM_MODULE_MEMORY_PROTECTION)
            {

                /* Modules with memory protection can only access block pools they created.  */
                status =  TXM_MODULE_INVALID;
                break;
            }
        }

        /* Loop to find the first matching byte pool.  */
        i = 0;
        byte_pool_ptr =  _tx_byte_pool_created_ptr;
        while (i < _tx_byte_pool_created_count)
        {

            /* Do we have a match?  */
            if (_txm_module_manager_object_name_compare(search_name, search_name_length, byte_pool_ptr -> tx_byte_pool_name))
            {

                /* Yes, we found it - return the necessary info!  */
                *object_ptr =  (VOID *) byte_pool_ptr;

                /* Set the the status to success!  */
                status =  TX_SUCCESS;
                break;
            }

            /* Increment the counter.  */
            i++;

            /* Move to next byte pool.  */
            byte_pool_ptr =  byte_pool_ptr -> tx_byte_pool_created_next;
        }
        break;
    }

    default:

        /* Invalid object ID.  */
        status =  TX_OPTION_ERROR;

        /* External Object pointer get.  */

#ifdef TXM_MODULE_ENABLE_NETX

        /* Determine if there is a NetX object get request.  */
        if ((object_type >= TXM_NETX_OBJECTS_START) && (object_type < TXM_NETX_OBJECTS_END))
        {

            /* Call the NetX module object get function.  */
            status =  _txm_module_manager_netx_object_pointer_get(object_type, search_name, search_name_length, object_ptr);
        }
#endif

#ifdef TXM_MODULE_ENABLE_NETXDUO

        /* Determine if there is a NetX Duo object get request.  */
        if ((object_type >= TXM_NETXDUO_OBJECTS_START) && (object_type < TXM_NETXDUO_OBJECTS_END))
        {

            /* Call the NetX Duo module object get function.  */
            status =  _txm_module_manager_netxduo_object_pointer_get(object_type, search_name, search_name_length, object_ptr);
        }
#endif

#ifdef TXM_MODULE_ENABLE_FILEX

        /* Determine if there is a FileX object get request.  */
        if ((object_type >= TXM_FILEX_OBJECTS_START) && (object_type < TXM_FILEX_OBJECTS_END))
        {

            /* Call the FileX module object get function.  */
            status =  _txm_module_manager_filex_object_pointer_get(object_type, search_name, search_name_length, object_ptr);
        }
#endif


#ifdef TXM_MODULE_ENABLE_GUIX

        /* Determine if there is a GUIX object get request.  */
        if ((object_type >= TXM_GUIX_OBJECTS_START) && (object_type < TXM_GUIX_OBJECTS_END))
        {

            /* Call the GUIX module object get function.  */
            status =  _txm_module_manager_guix_object_pointer_get(object_type, search_name, search_name_length, object_ptr);
        }
#endif

#ifdef TXM_MODULE_ENABLE_USBX

        /* Determine if there is a USBX object get request.  */
        if ((object_type >= TXM_USBX_OBJECTS_START) && (object_type < TXM_USBX_OBJECTS_END))
        {

            /* Call the USBX object get function.  */
            status =  _txm_module_manager_usbx_object_pointer_get(object_type, search_name, search_name_length, object_ptr);
        }
#endif

        break;
    }

    /* Disable interrupts.  */
    TX_DISABLE

    /* Enable preemption again.  */
    _tx_thread_preempt_disable--;

    /* Restore interrupts.  */
    TX_RESTORE

    /* Check for preemption.  */
    _tx_thread_system_preempt_check();

    /* Return success.  */
    return(status);
}