File: raddebug.c

package info (click to toggle)
radlib 2.12.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,132 kB
  • sloc: ansic: 15,843; sh: 8,102; makefile: 501
file content (121 lines) | stat: -rw-r--r-- 2,961 bytes parent folder | download | duplicates (3)
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
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>

#include <radsysdefs.h>
#include <radbuffers.h>
#include <radsemaphores.h>
#include <radsystem.h>
#include <radprocess.h>
#include <radmsgRouter.h>

static void msgHandler
(
    char        *srcQueueName,
    UINT        msgType,
    void        *msg,
    UINT        length,
    void        *userData
)
{
    return;
}

static void evtHandler
(
    UINT        eventsRx,
    UINT        rxData,
    void        *userData
)
{
    return;
}

static void USAGE (void)
{
    printf ("USAGE: raddebug [radlibSystemID] <msgRouterWorkDir>\n");
    printf ("           radlibSystemID    - (required) radlib system ID (1-255) to debug\n");
    printf ("           msgRouterWorkDir  - (optional) radlib msg router working directory\n");
    return;
}

int main (int argc, char *argv[])
{
    int         sysID;
    char        qname[128], refname[128];

    if (argc < 2)
    {
        USAGE ();
        return 1;
    }
    sysID = atoi (argv[1]);

    if (sysID < 1 || sysID > 255)
    {
        printf ("Invalid system ID!\n");
        USAGE ();
        return 1;
    }

    if (radSystemInit ((UCHAR)sysID) == ERROR)
    {
        printf ("\nError: unable to attach to wview radlib system %d!\n",
                sysID);
        return 1;
    }

    printf ("\nAttached to radlib system %d: UP %s\n\n",
            sysID, radSystemGetUpTimeSTR (sysID));

    // dump out the system buffer info
    radBuffersDebug ();
    printf ("\n");

    // dump out semaphore info
    radSemDebug ();
    printf ("\n");

    // if the message router work directory was given, try to dump his stats
    if (argc > 2)
    {
        //  call the radlib process init function
        sprintf (qname, "%s/raddebugFIFO", argv[2]);
        sprintf (refname, "%s/raddebugFIFOREF", argv[2]);
        if (radProcessInit ("raddebug",
                            qname,
                            0,
                            FALSE,                     // FALSE => not as daemon
                            msgHandler,
                            evtHandler,
                            NULL)
            == ERROR)
        {
            printf ("radProcessInit failed\n");
            radSystemExit ((UCHAR)sysID);
            return 1;
        }

        if (radMsgRouterInit (argv[2]) == ERROR)
        {
            printf ("Invalid msg router work directory %s given or router not running!\n", 
                    argv[2]);
        }
        else
        {
            printf ("Dumping message router stats to the system log file...\n\n");
            radMsgRouterStatsDump ();
            radMsgRouterExit ();
        }

        radProcessExit ();
        unlink (qname);
        unlink (refname);
    }

    radSystemExit ((UCHAR)sysID);
    return 0;
}