Real2Virtual202111

٤Ƴ٤Ĥ
  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
 
-
!
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
-
|
-
|
-
!
-
!
-
!
-
!
-
!
!
|
-
 
 
 
 
 
 
 
-
|
|
!
 
-
|
!
 
-
|
!
 
!
|
-
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
-
-
|
!
!
-
-
-
|
|
!
!
!
 
-
|
!
 
-
-
-
|
|
|
|
!
!
|
!
 
-
|
!
 
!
|
-
 
-
!
 
 
 
!
|
-
-
|
!
 
!
-
 
 
 
!
-
 
 
-
!
-
!
 
 
!
|
#include "StringQueue.h"
//#include <string.h>
 
//void initForStringQueue(struct stringQueue *this);
/*
 
              0                       QMax-1
              +--------------------------+
   squeueMem0 |                          |
              +--------------------------+
 
              0                       QMax-1
              +--------------------------+
   squeueMem1 |                          |
              +--------------------------+
 
 
    squeue[0] -> squeueMem0 or squeueMem1
    squeue[1] -> squeueMem0 or squeueMem1
 
 
 
 */
 
StringQueue::StringQueue(void){
    int i;
    for(i=0;i<sqMax;i++){
   squeueMem[i][0]='\0';
//   squeueMem1[0]='\0';
   squeue[i]=(char *)NULL;
//   squeue[1]=(char *)NULL;
   faceIDs[i]=-1;
//   faceIDs[1]=-1;
   status[i]=0;
//   status[1]=0;
   squeueLength[i]=0;
//   squeueLength[1]=0;
    }
}
 
int StringQueue::putSQueue( int fid, char *x, int lx){
    int i;
    int q=getQueue(fid);
    if(q<0) return 0;
    int st=status[q];
    if(st==2) return 0;
    if(st==0) status[q]=1;
    int lq=squeueLength[q];
    if(lx+lq>=QMax) {
        clearQueue(q);
        return 0;
    }
    char *s=squeue[q];
    for(i=0;i<=lx;i++){
        s[lq+i]=x[i];
    }
    squeueLength[q]=lq+lx;
    if(x[lx]=='\0'){
        status[q]=2;
    }
    return 1;
}
 
int StringQueue::getQueue( int fid){
    int q=-1;
    /*
    if(faceIDs[0]==fid){
        q=0;
    }
    else
    if(faceIDs[1]==fid){
        q=1;
    }
    else
    if(status[0]==0){
        q=0;
        faceIDs[q]=fid;
    }
    else
    if(status[1]==0){
        q=1;
        faceIDs[q]=fid;
    }
    if(q<0) return -1;
 
    if(status[q]==2){
        return -1;
    }
*/
  for(int i=0;i<sqMax;i++){
      if(faceIDs[i]==fid){
              q=i;
        }
    }
    if(q<0){
        for(int i=0;i<sqMax;i++){
               if(status[i]==0){
                     q=i;
                      faceIDs[q]=fid;
                 }
        }
    }
    if(q<0)  return -1;
    if(status[q]==2){
         return -1;
    }
    
    if(status[q]==0){
        for(int i=0;i<sqMax; i++){
        if( squeueMem[i][0] == '\0'){
            squeue[q]=squeueMem[i];
            squeueLength[q]=0;
            status[q]=1;                
                return q;
          }
        }
        return -1;
    }
    else
    if(status[q]==1){
        return q;
    }
    return -1;
}
 
void StringQueue::clearQueue( int q){
    status[q]=0;
//    int fid=faceIDs[q];
    char *s=squeue[q];
    squeue[q]=(char *)NULL;
    s[0]='\0';
    faceIDs[q]=-1;
}
 
int StringQueue::getReadyQ(void){
    for(int i=0;i<sqMax; i++){
      if(status[i]==2) return i;
    }
    return -1;
}
/*
   return: face ID (fid) of the received command.
           -1 if there is no command in the queue.
   x: received command in the queue
 */
int StringQueue::getSQueue( char *x){
    int q=getReadyQ();
    if(q<0) return -1;
//    int st=status[q];
    int fid=faceIDs[q];
//    strcpy(x,squeue[q]);
    xstrcpy(x,squeue[q]);
    clearQueue(q);
    return fid;
}
 

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS