1/* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18/**
19 *  @file oscl_uuid.h
20 *  @brief This file defines the OSCL UUID structure used for unique
21 *  identifiers as well as the short (32-bit) identifiers OsclUid32.
22 */
23
24#ifndef OSCL_UUID_H_INCLUDED
25#define OSCL_UUID_H_INCLUDED
26
27#ifndef OSCL_BASE_H_INCLUDED
28#include "oscl_base.h"
29#endif
30
31#ifndef OSCL_MEM_BASIC_FUNCTIONS_H
32#include "oscl_mem_basic_functions.h"
33#endif
34
35#ifndef OSCL_STRING_UTILS_H
36#include "oscl_string_utils.h"
37#endif
38
39#ifndef OSCL_STDSTRING_H_INCLUDED
40#include "oscl_stdstring.h"
41#endif
42// __cplusplus
43
44typedef uint32 OsclUid32;
45const char PV_CHAR_CLOSE_BRACKET = ')';
46const char PV_CHAR_COMMA = ',';
47/**
48 * OSCL UUID structure used for unique identification of modules and interfaces.
49 */
50struct OsclUuid
51{
52#define BYTES_IN_UUID_ARRAY 8
53
54    OsclUuid()
55    {
56        oscl_memset(this, 0, sizeof(OsclUuid));
57    }
58
59    OsclUuid(uint32 l, uint16 w1, uint16 w2, uint8 b1, uint8 b2, uint8 b3,
60             uint8 b4, uint8 b5, uint8 b6, uint8 b7, uint8 b8)
61    {
62        data1 = l;
63        data2 = w1;
64        data3 = w2;
65        data4[0] = b1;
66        data4[1] = b2;
67        data4[2] = b3;
68        data4[3] = b4;
69        data4[4] = b5;
70        data4[5] = b6;
71        data4[6] = b7;
72        data4[7] = b8;
73    }
74
75    //The OSCL UUID structure takes in a string parameter
76    //Expected string input for the OsclString should be like:
77    //(0xa054569c,0x24c5,0x452e,0x99,0x77,0x87,0x4b,0xca,0x79,0xd3,0xaf)
78
79    OsclUuid(const char* aUuidString)
80    {
81        //Initialize all data members to 0 to begin with
82        data1 = data2 = data3 = 0;
83
84        for (int ii = 0; ii < 8; ++ii)
85        {
86            data4[ii] = 0;
87        }
88
89        int uuidStrLen = oscl_strlen(aUuidString);
90
91        if (uuidStrLen != 0)
92        {
93            const char* sptr = NULL, *eptr = NULL;
94            int commaval = 0;
95            sptr = aUuidString;
96            ++sptr; //Increment over the starting parantheses '('
97            eptr = sptr;
98            for (int i = 0; i < uuidStrLen - 1 ; ++i)
99            {
100                if ((*eptr != PV_CHAR_COMMA) && (*eptr != PV_CHAR_CLOSE_BRACKET)) //Increment the pointer unless you get to the ","
101                {                               //The comma signifies the beginning of the new OsclUuid parameter
102                    ++eptr;
103                }
104                else
105                {
106                    sptr = sptr + 2;//Move over the 0x characters in the beginning of the hex value;
107                    ++commaval;
108                    switch (commaval)
109                    {
110                        case 1:
111                        {
112                            PV_atoi(sptr , 'x', eptr - sptr, data1);
113                            break;
114                        }
115                        case 2:
116                        {
117                            uint32 tempdata2 = 0;
118                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata2);
119                            data2 = (uint16)tempdata2;
120                            break;
121                        }
122                        case 3:
123                        {
124                            uint32 tempdata3 = 0;
125                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata3);
126                            data3 = (uint16)tempdata3;
127                            break;
128                        }
129                        case 4:
130                        {
131                            uint32 tempdata4_0 = 0;
132                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata4_0);
133                            data4[0] = (uint8)tempdata4_0;
134                            break;
135                        }
136                        case 5:
137                        {
138                            uint32 tempdata4_1 = 0;
139                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata4_1);
140                            data4[1] = (uint8)tempdata4_1;
141                            break;
142                        }
143                        case 6:
144                        {
145                            uint32 tempdata4_2 = 0;
146                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata4_2);
147                            data4[2] = (uint8)tempdata4_2;
148                            break;
149                        }
150                        case 7:
151                        {
152                            uint32 tempdata4_3 = 0;
153                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata4_3);
154                            data4[3] = (uint8)tempdata4_3;
155                            break;
156                        }
157                        case 8:
158                        {
159                            uint32 tempdata4_4 = 0;
160                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata4_4);
161                            data4[4] = (uint8)tempdata4_4;
162                            break;
163                        }
164                        case 9:
165                        {
166                            uint32 tempdata4_5 = 0;
167                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata4_5);
168                            data4[5] = (uint8)tempdata4_5;
169                            break;
170                        }
171                        case 10:
172                        {
173                            uint32 tempdata4_6 = 0;
174                            PV_atoi(sptr , 'x', (eptr - sptr), tempdata4_6);
175                            data4[6] = (uint8)tempdata4_6;
176                            break;
177                        }
178                        case 11:
179                        {
180                            uint32 tempdata4_7 = 0;
181                            PV_atoi(sptr, 'x', (eptr - sptr), tempdata4_7);
182                            data4[7] = (uint8)tempdata4_7;
183                            break;
184                        }
185                    }
186                    if (*eptr == PV_CHAR_CLOSE_BRACKET) //Break from the loop on finding
187                    {
188                        break;
189                    }
190                    ++eptr;
191                    sptr = eptr;
192                }
193            }
194        }
195    }
196
197    OsclUuid(const OsclUuid &uuid)
198    {
199        oscl_memcpy(this, &uuid, sizeof(OsclUuid));
200    }
201
202    OsclUuid &operator=(const OsclUuid& src)
203    {
204        oscl_memcpy(this, &src, sizeof(OsclUuid));
205        return *this;
206    }
207
208    bool operator==(const OsclUuid& src) const
209    {
210        if (data1 != src.data1 || data2 != src.data2 || data3 != src.data3)
211        {
212            return false;
213        }
214
215        for (int ii = 0; ii < 8; ++ii)
216        {
217            if (data4[ii] != src.data4[ii])
218            {
219                return false;
220            }
221        }
222
223        return true;
224    }
225
226    bool operator!=(const OsclUuid &src) const
227    {
228        return !(*this == src);
229    }
230
231    uint32  data1;
232    uint16  data2;
233    uint16  data3;
234    uint8   data4[BYTES_IN_UUID_ARRAY];
235};
236
237#endif
238
239