summaryrefslogtreecommitdiffstats
path: root/schedsim/shell/shared/lookup_task.c
blob: 264ffa82f819be368980870b2f2d7f8f1bc6dca5 (plain) (blame)
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
/*
 *  Given Name or ID String, give Id
 *
 *  COPYRIGHT (c) 1989-2013.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>

#include <rtems.h>
#include <rtems/stringto.h>
#include <rtems/score/threaddispatch.h>

#ifndef METHOD_NAME
  #define METHOD_NAME lookup_task
#endif
#ifndef RTEMS_IDENT_NAME
  #define RTEMS_IDENT_NAME rtems_task_ident
  #define DOING_TASKS
#endif

int METHOD_NAME(
  const char *string,
  rtems_id   *id
)
{
  char               name[5];
  rtems_status_code  status;
  unsigned long      tmp;

  if ( string[0] != '0' ) {
    #ifdef DOING_TASKS
      if ( !strcmp( string, "SELF" ) ) {
        _Thread_Disable_dispatch();
          *id = _Thread_Executing->Object.id;
        _Thread_Enable_dispatch();
        return 0;
      }
    #endif
    if ( strlen( string ) != 4 ) {
      return -1;
    }
    memset( name, '\0', sizeof(name) );
    strncpy( name, string, 4 );
    status = RTEMS_IDENT_NAME(
      rtems_build_name( name[0], name[1], name[2], name[3] ),
      OBJECTS_SEARCH_ALL_NODES,
      id
    );
    if ( status != RTEMS_SUCCESSFUL )
      return 1;
  } else {
    if ( rtems_string_to_unsigned_long( string, &tmp, NULL, 0) ) {
      fprintf( stderr, "Argument (%s) is not a number\n", string );
      return 1;
    }
    *id = (rtems_id) tmp;
  }

  return 0;
}