summaryrefslogtreecommitdiff
path: root/utility/demo-fw/common/dfm_entry.c
blob: f70c2f66e8b851671d7cf665217533dd62e2ee76 (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

#include "dfm_entry.h"
#include "dfm_cmd.h"

//-----------------------------------------------------------------------------
///           Internal Variables                   
//-----------------------------------------------------------------------------


#ifndef NULL
#define NULL 0
#endif

//point to first input entry
static TInputEntry *gpFirstInputEntry = NULL;

//-----------------------------------------------------------------------------
///           Exported Function                   
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
/// register prompt display entry fucntion into prompt list for calling
/// The image should be same size as the LCD.
/// \param pPromptFunc, pointer to global variable of prompt display function
/// \return 0 success, other value fail
//------------------------------------------------------------------------------
int RegisterInputEntry(TInputEntry *pEntryStruct)
{
  TInputEntry *pTmpEntry;
  
  pTmpEntry = gpFirstInputEntry;
  
  if(pTmpEntry == NULL) {
    gpFirstInputEntry = pEntryStruct;
    gpFirstInputEntry->next  = NULL;
    
    return 0;
  }
  
  while(pTmpEntry->next != NULL)
    pTmpEntry = pTmpEntry->next;
  
  pTmpEntry->next = pEntryStruct;
  pEntryStruct->next = NULL;
  
  return 0;
}

//-----------------------------------------------------------------------------
/// Calling prompt display entry chained in prompt list 
/// \return 0 success, other value fail
//------------------------------------------------------------------------------
int ShowPrompt()
{
  TInputEntry *pTmpEntry;
  
  pTmpEntry = gpFirstInputEntry;
  while(pTmpEntry != NULL) {
    //printf("\n\r ********DisplayPrompt********* "); 
    if(pTmpEntry->Prompt)
      pTmpEntry->Prompt();
    pTmpEntry = pTmpEntry->next;
  }
  
  return 0;
}

//-----------------------------------------------------------------------------
/// Check if any command is ready in all input entry, if yes, set the flag
/// \return 0 no command ready, other means yes and value represents number of
///   ready input entry
//------------------------------------------------------------------------------
unsigned int CommandIsReady()
{
  unsigned int ret = 0;
  TInputEntry *pTmpEntry;
  
  pTmpEntry = gpFirstInputEntry;
  while(pTmpEntry != NULL) {
    if(pTmpEntry->CommandIsReady && pTmpEntry->CommandIsReady()) {
      pTmpEntry->readyFlag = 1;
      ++ ret;
    }
    
    pTmpEntry = pTmpEntry->next;
  }
  
  return ret;  
}

//-----------------------------------------------------------------------------
/// Get Command Queue
/// \return 0 no command ready, other means ready and value is available numbers
//------------------------------------------------------------------------------
TCmdQueue * GetCommandQueue()
{
  TInputEntry *pTmpEntry;
  TCmdQueue *pQueueFirst, *pTmpQueue = NULL;
  
  pTmpEntry = gpFirstInputEntry;
  while(pTmpEntry != NULL) {
    //check if command ready flag is set
    if(pTmpEntry->readyFlag) {

      if(pTmpQueue == NULL) {
        //Set pointer to first available command element of queue
        pQueueFirst = &(pTmpEntry->CmdElement);
        pTmpQueue = pQueueFirst;
      } else {
        pTmpQueue->next = &(pTmpEntry->CmdElement);
        pTmpQueue = pTmpQueue->next;
      }
      
      pTmpQueue->command = pTmpEntry->GetCommand();
      pTmpQueue->next = NULL;
      
      pTmpEntry->readyFlag = 0;
    }
    
    pTmpEntry = pTmpEntry->next;
  }
      
  return pQueueFirst;
}

//-----------------------------------------------------------------------------
/// Run Command Queue
/// \return 0 success for all, other value fail
//------------------------------------------------------------------------------
int RunCommandQueue(TCmdQueue *pCmdQueue)
{
  int ret = 0;
  TCmdQueue *pTmpQueue;
  
  pTmpQueue = pCmdQueue;
  while(pTmpQueue != NULL) {
    ret |= ParseAndRunMultiCmds(pTmpQueue->command);
    pTmpQueue = pTmpQueue->next;
  }
  
  return ret;  
}
personal git repositories of Harald Welte. Your mileage may vary