00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <scheduler.h>
00054 #include "p802_15_4hlist.h"
00055
00056
00057 int addHListLink(HLISTLINK **hlistLink1, HLISTLINK **hlistLink2, UINT_16 hostid, UINT_8 sn)
00058 {
00059 HLISTLINK *tmp;
00060 if(*hlistLink2 == NULL)
00061 {
00062 *hlistLink2 = new HLISTLINK(hostid, sn);
00063 if (*hlistLink2 == NULL) return 1;
00064 *hlistLink1 = *hlistLink2;
00065 }
00066 else
00067 {
00068 tmp=new HLISTLINK(hostid, sn);
00069 if (tmp == NULL) return 1;
00070 tmp->last = *hlistLink2;
00071 (*hlistLink2)->next = tmp;
00072 *hlistLink2 = tmp;
00073 }
00074 return 0;
00075 }
00076
00077 int updateHListLink(int oper, HLISTLINK **hlistLink1, HLISTLINK **hlistLink2, UINT_16 hostid, UINT_8 sn)
00078 {
00079 HLISTLINK *tmp;
00080 int ok;
00081
00082 ok = 1;
00083
00084 tmp = *hlistLink1;
00085 while(tmp != NULL)
00086 {
00087 if(tmp->hostID == hostid)
00088 {
00089 if (oper == hl_oper_del)
00090 {
00091 if(tmp->last != NULL)
00092 {
00093 tmp->last->next = tmp->next;
00094 if(tmp->next != NULL)
00095 tmp->next->last = tmp->last;
00096 else
00097 *hlistLink2 = tmp->last;
00098 }
00099 else if (tmp->next != NULL)
00100 {
00101 *hlistLink1 = tmp->next;
00102 tmp->next->last = NULL;
00103 }
00104 else
00105 {
00106 *hlistLink1 = NULL;
00107 *hlistLink2 = NULL;
00108 }
00109 delete tmp;
00110 }
00111 if (oper == hl_oper_rpl)
00112 {
00113 if (tmp->SN != sn)
00114 tmp->SN = sn;
00115 else
00116 {
00117 ok = 2;
00118 break;
00119 }
00120 }
00121 ok = 0;
00122 break;
00123 }
00124 tmp = tmp->next;
00125 }
00126 return ok;
00127 }
00128
00129 int chkAddUpdHListLink(HLISTLINK **hlistLink1, HLISTLINK **hlistLink2, UINT_16 hostid, UINT_8 sn)
00130 {
00131 int i;
00132
00133 i = updateHListLink(hl_oper_rpl, hlistLink1, hlistLink2, hostid, sn);
00134 if (i == 0) return 1;
00135 else if (i == 2) return 2;
00136
00137 i = addHListLink(hlistLink1, hlistLink2, hostid, sn);
00138 if (i == 0) return 0;
00139 else return 3;
00140 }
00141
00142 void emptyHListLink(HLISTLINK **hlistLink1, HLISTLINK **hlistLink2)
00143 {
00144 HLISTLINK *tmp, *tmp2;
00145
00146 if(*hlistLink1 != NULL)
00147 {
00148 tmp = *hlistLink1;
00149 while(tmp != NULL)
00150 {
00151 tmp2 = tmp;
00152 tmp = tmp->next;
00153 delete tmp2;
00154 }
00155 *hlistLink1 = NULL;
00156 }
00157 *hlistLink2 = *hlistLink1;
00158 }
00159
00160 void dumpHListLink(HLISTLINK *hlistLink1, UINT_16 hostid)
00161 {
00162 HLISTLINK *tmp;
00163 int i;
00164
00165 fprintf(stdout, "[%.2f] --- dump host list (by host %d) ---\n", Scheduler::instance().clock(), hostid);
00166 tmp = hlistLink1;
00167 i = 1;
00168 while(tmp != NULL)
00169 {
00170 fprintf(stdout, "\t%d:\tfrom host %d:\tSN = %d\n", i, tmp->hostID, tmp->SN);
00171 tmp = tmp->next;
00172 i++;
00173 }
00174 }
00175
00176