xref: /haiku/docs/develop/servers/app_server/TokenHandler.rst (revision a5061ecec55353a5f394759473f1fd6df04890da)
1*a5061eceSAdrien DestuguesTokenHandler class
2*a5061eceSAdrien Destugues##################
3*a5061eceSAdrien Destugues
4*a5061eceSAdrien DestuguesThis is a simple way to provide tokens for various reasons.
5*a5061eceSAdrien Destugues
6*a5061eceSAdrien DestuguesMember Functions
7*a5061eceSAdrien Destugues================
8*a5061eceSAdrien Destugues
9*a5061eceSAdrien DestuguesTokenHandler(void)
10*a5061eceSAdrien Destugues------------------
11*a5061eceSAdrien Destugues
12*a5061eceSAdrien Destugues1. Initialize the index to -1
13*a5061eceSAdrien Destugues2. create the access semaphore
14*a5061eceSAdrien Destugues3. create the exclude list with no items
15*a5061eceSAdrien Destugues
16*a5061eceSAdrien Destugues~TokenHandler(void)
17*a5061eceSAdrien Destugues-------------------
18*a5061eceSAdrien Destugues
19*a5061eceSAdrien Destugues1. delete the access lock
20*a5061eceSAdrien Destugues2. call ResetExcludes and delete the exclude list
21*a5061eceSAdrien Destugues
22*a5061eceSAdrien Destuguesint32 GetToken(void)
23*a5061eceSAdrien Destugues--------------------
24*a5061eceSAdrien Destugues
25*a5061eceSAdrien DestuguesReturns a unique token which is not equal to any excluded values
26*a5061eceSAdrien Destugues
27*a5061eceSAdrien Destugues1. create a local variable to return the new token
28*a5061eceSAdrien Destugues2. acquire the access semaphore
29*a5061eceSAdrien Destugues3. Increment the internal index
30*a5061eceSAdrien Destugues4. while IsExclude(index) is true, increment the index
31*a5061eceSAdrien Destugues5. assign it to the local variable
32*a5061eceSAdrien Destugues6. release the access semaphore
33*a5061eceSAdrien Destugues7. return the local variable
34*a5061eceSAdrien Destugues
35*a5061eceSAdrien Destuguesvoid Reset(void)
36*a5061eceSAdrien Destugues----------------
37*a5061eceSAdrien Destugues
38*a5061eceSAdrien Destugues1. acquire the access semaphore
39*a5061eceSAdrien Destugues2. set the internal index to -1
40*a5061eceSAdrien Destugues3. release the access semaphore
41*a5061eceSAdrien Destugues
42*a5061eceSAdrien Destuguesvoid ExcludeValue(int32 value)
43*a5061eceSAdrien Destugues------------------------------
44*a5061eceSAdrien Destugues
45*a5061eceSAdrien Destugues1. acquire the access semaphore
46*a5061eceSAdrien Destugues2. if IsExclude(value) is false, add it to the exclude list
47*a5061eceSAdrien Destugues3. release the access semaphore
48*a5061eceSAdrien Destugues
49*a5061eceSAdrien Destuguesvoid ResetExcludes(void)
50*a5061eceSAdrien Destugues------------------------
51*a5061eceSAdrien Destugues
52*a5061eceSAdrien Destugues1. acquire the access semaphore
53*a5061eceSAdrien Destugues2. Iterate through the exclude list, removing and deleting each item
54*a5061eceSAdrien Destugues3. release the access semaphore
55*a5061eceSAdrien Destugues
56*a5061eceSAdrien Destuguesbool IsExclude(int32 value)
57*a5061eceSAdrien Destugues---------------------------
58*a5061eceSAdrien Destugues
59*a5061eceSAdrien Destugues1. create a boolean match flag and set it to false
60*a5061eceSAdrien Destugues2. acquire the access semaphore
61*a5061eceSAdrien Destugues3. iterate through the exclude list and see if the value matches any in
62*a5061eceSAdrien Destugues   the list
63*a5061eceSAdrien Destugues4. If there is a match, set the match flag to true and exit the loop
64*a5061eceSAdrien Destugues5. release the access semaphore
65*a5061eceSAdrien Destugues6. return the match flag
66*a5061eceSAdrien Destugues
67