YAUID.xs

filter: Statementstmt 36.5% 87 / 238 Branchbran 29.4% 30 / 102 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 34.4% 117 / 340 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Number/YAUID.pm ↑ Summary
1 //
2 //
3 // Created by Alexander Borisov on 22.07.14.
4 // Copyright (c) 2014 Alexander Borisov. All rights reserved.
5 //
6  
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10  
11 #include <yauid.h>
12  
13 #ifdef ENVIRONMENT32
14 #error 64 bit system only
15 #else
16  
17 char error_text[][64] = {
18 "OK",
19 "Can't create key file",
20 "Can't open key file",
21 "All key in current sec done",
22 "Can't read size for file node_id",
23 "Can't allocate memory for node_id",
24 "File node_id not exists",
25 "Can't set lock",
26 "Node_id is too long",
27 "Node_id is too short",
28 "Can't read key from file",
29 "Can't seek to start file position",
30 "Can't write key to file",
31 "Can't flush key to file",
32 "Number of attempts to get the key exhausted",
33 "Can't create object"
34 };
35  
36 0 unsigned long yauid_get_inc_id(hkey_t key)
37 {
38 0 key <<= (BIT_LIMIT_TIMESTAMP + BIT_LIMIT_NODE);
39 0 key >>= (BIT_LIMIT - BIT_LIMIT_INC);
40
41 0 return (unsigned long)(key);
42 }
43  
44 0 unsigned long yauid_get_node_id(hkey_t key)
45 {
46 0 key <<= BIT_LIMIT_TIMESTAMP;
47 0 key >>= (BIT_LIMIT - BIT_LIMIT_NODE);
48
49 0 return (unsigned long)(key);
50 }
51  
52 0 unsigned long yauid_get_timestamp(hkey_t key)
53 {
54 0 key >>= (BIT_LIMIT_NODE + BIT_LIMIT_INC);
55
56 0 return (unsigned long)(key);
57 }
58  
59 0 unsigned long long int yauid_get_max_node_id()
60 {
61 0 return NUMBER_LIMIT_NODE;
62 }
63  
64 0 unsigned long long int yauid_get_max_inc()
65 {
66 0 return NUMBER_LIMIT;
67 }
68  
69 0 unsigned long long int yauid_get_max_timestamp()
70 {
71 0 return NUMBER_LIMIT_TIMESTAMP;
72 }
73  
74 1000 hkey_t yauid_get_key(yauid* yaobj)
75 {
76 1000 hkey_t key = (hkey_t)(0);
77 1000 unsigned int count = 0;
78
79 for(;;)
80 {
81 1000 ▶ if((key = yauid_get_key_once(yaobj)) == (hkey_t)(0))
Branch: 1 branch
BranchTrueFalseTotal
if((key = yauid_get_key_once(yaobj)) == (hkey_t)(0)) 0 1000 1000
82 {
83 0 ▶ if(yaobj->error == YAUID_ERROR_KEYS_ENDED)
Branch: 1 branch
BranchTrueFalseTotal
if(yaobj->error == YAUID_ERROR_KEYS_ENDED) 0 0 0
84 {
85 0 count++;
86
87 0 ▶ if(yaobj->try_count && count >= yaobj->try_count)
Branch: 2 branches
BranchTrueFalseTotal
if(yaobj->try_count && count >= yaobj->try_count) 0 0 0
if(yaobj->try_count && count >= yaobj->try_count) 0 0 0
88 {
89 0 yaobj->error = YAUID_ERROR_TRY_COUNT_KEY;
90 0 break;
91 }
92
93 0 usleep(yaobj->sleep_usec);
94 0 continue;
95 }
96 }
97
98 1000 break;
99 }
100
101 1000 return key;
102 }
103  
104 1000 hkey_t yauid_get_key_once(yauid* yaobj)
105 {
106 1000 hkey_t key = (hkey_t)(0), tmp = (hkey_t)(1), ltime = (hkey_t)(0);
107
108 1000 ▶ if(yaobj->node_id < LIMIT_MIN_NODE_ID)
Branch: 1 branch
BranchTrueFalseTotal
if(yaobj->node_id < LIMIT_MIN_NODE_ID) 0 1000 1000
109 {
110 0 yaobj->error = YAUID_ERROR_SHORT_NODE_ID;
111 0 return key;
112 }
113 1000 ▶ else if(yaobj->node_id > NUMBER_LIMIT_NODE)
Branch: 1 branch
BranchTrueFalseTotal
else if(yaobj->node_id > NUMBER_LIMIT_NODE) 0 1000 1000
114 {
115 0 yaobj->error = YAUID_ERROR_LONG_NODE_ID;
116 0 return key;
117 }
118
119 1000 yaobj->error = YAUID_OK;
120
121 1000 ▶ if(flock(yaobj->i_lockfile, LOCK_EX) == -1)
Branch: 1 branch
BranchTrueFalseTotal
if(flock(yaobj->i_lockfile, LOCK_EX) == -1) 0 1000 1000
122 {
123 0 yaobj->error = YAUID_ERROR_FILE_LOCK;
124 0 return (hkey_t)(0);
125 }
126
127 1000 ▶ if(fseek(yaobj->h_lockfile, 0, SEEK_SET) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if(fseek(yaobj->h_lockfile, 0, SEEK_SET) != 0) 0 1000 1000
128 {
129 0 yaobj->error = YAUID_ERROR_FILE_SEEK;
130 0 return (hkey_t)(0);
131 }
132
133 1000 ▶ if(fread((void *)(&key), sizeof(hkey_t), 1, yaobj->h_lockfile) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if(fread((void *)(&key), sizeof(hkey_t), 1, yaobj->h_lockfile) != 1) 1 999 1000
134 {
135 1 ▶ if(fseek(yaobj->h_lockfile, 0L, SEEK_END) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if(fseek(yaobj->h_lockfile, 0L, SEEK_END) != 0) 0 1 1
136 {
137 0 yaobj->error = YAUID_ERROR_FILE_SEEK;
138 0 return (hkey_t)(0);
139 }
140
141 1 long h_size = ftell(yaobj->h_lockfile);
142 1 ▶ if(h_size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if(h_size > 0) 0 1 1
143 {
144 0 yaobj->error = YAUID_ERROR_READ_KEY;
145 0 return (hkey_t)(0);
146 }
147
148 1 ▶ if(fseek(yaobj->h_lockfile, 0, SEEK_SET) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if(fseek(yaobj->h_lockfile, 0, SEEK_SET) != 0) 0 1 1
149 {
150 0 yaobj->error = YAUID_ERROR_FILE_SEEK;
151 0 return (hkey_t)(0);
152 }
153 }
154
155 1000 ltime = time(NULL);
156
157 1000 ▶ if(key)
Branch: 1 branch
BranchTrueFalseTotal
if(key) 999 1 1000
158 {
159 999 tmp = key >> (BIT_LIMIT_NODE + BIT_LIMIT_INC);
160 999 key <<= (BIT_LIMIT_TIMESTAMP + BIT_LIMIT_NODE);
161 999 key >>= (BIT_LIMIT - BIT_LIMIT_INC);
162
163 999 key++;
164
165 999 ▶ if(tmp == ltime)
Branch: 1 branch
BranchTrueFalseTotal
if(tmp == ltime) 999 0 999
166 {
167 999 ▶ if(key > (hkey_t)(NUMBER_LIMIT))
Branch: 1 branch
BranchTrueFalseTotal
if(key > (hkey_t)(NUMBER_LIMIT)) 0 999 999
168 {
169 0 flock(yaobj->i_lockfile, LOCK_UN);
170
171 0 yaobj->error = YAUID_ERROR_KEYS_ENDED;
172 0 return (hkey_t)(0);
173 }
174
175 999 tmp = key;
176 }
177 else
178 0 tmp = (hkey_t)(1);
179 }
180
181 1000 key = ltime;
182 1000 key <<= BIT_LIMIT_NODE;
183
184 1000 key |= yaobj->node_id;
185 1000 key <<= BIT_LIMIT_INC;
186
187 1000 key |= tmp;
188
189 1000 ▶ if(fseek(yaobj->h_lockfile, 0, SEEK_SET) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if(fseek(yaobj->h_lockfile, 0, SEEK_SET) != 0) 0 1000 1000
190 {
191 0 yaobj->error = YAUID_ERROR_FILE_SEEK;
192 0 return (hkey_t)(0);
193 }
194
195 1000 ▶ if(fwrite((const void *)(&key), sizeof(hkey_t), 1, yaobj->h_lockfile) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if(fwrite((const void *)(&key), sizeof(hkey_t), 1, yaobj->h_lockfile) != 1) 0 1000 1000
196 {
197 0 yaobj->error = YAUID_ERROR_WRITE_KEY;
198 0 return (hkey_t)(0);
199 }
200
201 1000 ▶ if(fflush(yaobj->h_lockfile) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if(fflush(yaobj->h_lockfile) != 0) 0 1000 1000
202 {
203 0 yaobj->error = YAUID_ERROR_FLUSH_KEY;
204 0 return (hkey_t)(0);
205 }
206
207 1000 ▶ if(flock(yaobj->i_lockfile, LOCK_UN) == -1)
Branch: 1 branch
BranchTrueFalseTotal
if(flock(yaobj->i_lockfile, LOCK_UN) == -1) 0 1000 1000
208 {
209 0 yaobj->error = YAUID_ERROR_FILE_LOCK;
210 0 return (hkey_t)(0);
211 }
212
213 1000 yaobj->error = YAUID_OK;
214
215 1000 return key;
216 }
217  
218 1 yauid * yauid_init(const char *filepath_key, const char *filepath_node_id)
219 {
220 1 yauid* yaobj = (yauid *)malloc(sizeof(yauid));
221
222 1 ▶ if(yaobj)
Branch: 1 branch
BranchTrueFalseTotal
if(yaobj) 1 0 1
223 {
224 1 yaobj->node_id = 0;
225 1 yaobj->error = YAUID_OK;
226 1 yaobj->c_lockfile = filepath_key;
227 1 yaobj->i_lockfile = 0;
228 1 yaobj->h_lockfile = NULL;
229 1 yaobj->try_count = 0;
230 1 yaobj->sleep_usec = (useconds_t)(35000L);
231
232 1 ▶ if(filepath_node_id != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(filepath_node_id != NULL) 0 1 1
233 {
234 0 ▶ if(access( filepath_node_id, F_OK ) != -1)
Branch: 1 branch
BranchTrueFalseTotal
if(access( filepath_node_id, F_OK ) != -1) 0 0 0
235 {
236 FILE* h_node_id;
237 0 ▶ if((h_node_id = fopen(filepath_node_id, "rb")))
Branch: 1 branch
BranchTrueFalseTotal
if((h_node_id = fopen(filepath_node_id, "rb"))) 0 0 0
238 {
239 0 fseek(h_node_id, 0L, SEEK_END);
240
241 0 long h_size = ftell(h_node_id);
242 0 ▶ if(h_size <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if(h_size <= 0) 0 0 0
243 {
244 0 fclose(h_node_id);
245 0 yaobj->error = YAUID_ERROR_FILE_NODE_ID;
246 0 return yaobj;
247 }
248
249 0 fseek(h_node_id, 0L, SEEK_SET);
250
251 0 char *text = (char *)malloc(sizeof(char) * (h_size + 1));
252 0 ▶ if(text == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(text == NULL) 0 0 0
253 {
254 0 fclose(h_node_id);
255 0 yaobj->error = YAUID_ERROR_FILE_NODE_MEM;
256 0 return yaobj;
257 }
258
259 0 fread(text, sizeof(char), h_size, h_node_id);
260 0 fclose(h_node_id);
261
262 0 long i = 0;
263 0 ▶ for(i = 0; i < h_size; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < h_size; i++) 0 0 0
264 {
265 0 ▶ if(text[i] >= '0' && text[i] <= '9')
Branch: 2 branches
BranchTrueFalseTotal
if(text[i] >= '0' && text[i] <= '9') 0 0 0
if(text[i] >= '0' && text[i] <= '9') 0 0 0
266 0 yaobj->node_id = (text[i] - '0') + (yaobj->node_id * 10);
267 }
268
269 0 free(text);
270
271 0 ▶ if(yaobj->node_id < LIMIT_MIN_NODE_ID)
Branch: 1 branch
BranchTrueFalseTotal
if(yaobj->node_id < LIMIT_MIN_NODE_ID) 0 0 0
272 {
273 0 yaobj->error = YAUID_ERROR_SHORT_NODE_ID;
274 0 return yaobj;
275 }
276 0 ▶ else if(yaobj->node_id > NUMBER_LIMIT_NODE)
Branch: 1 branch
BranchTrueFalseTotal
else if(yaobj->node_id > NUMBER_LIMIT_NODE) 0 0 0
277 {
278 0 yaobj->error = YAUID_ERROR_LONG_NODE_ID;
279 0 return yaobj;
280 }
281 }
282 }
283 else {
284 0 yaobj->error = YAUID_ERROR_FILE_NODE_EXT;
285 0 return yaobj;
286 }
287 }
288
289 1 ▶ if(access( yaobj->c_lockfile, F_OK ) == -1)
Branch: 1 branch
BranchTrueFalseTotal
if(access( yaobj->c_lockfile, F_OK ) == -1) 1 0 1
290 {
291 1 ▶ if((yaobj->h_lockfile = fopen(yaobj->c_lockfile, "ab")) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if((yaobj->h_lockfile = fopen(yaobj->c_lockfile, "ab")) == 0) 0 1 1
292 {
293 0 yaobj->error = YAUID_ERROR_CREATE_KEY_FILE;
294 0 return yaobj;
295 }
296
297 1 fclose(yaobj->h_lockfile);
298 }
299
300 1 ▶ if((yaobj->h_lockfile = fopen(yaobj->c_lockfile, "rb+")) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if((yaobj->h_lockfile = fopen(yaobj->c_lockfile, "rb+")) == 0) 0 1 1
301 {
302 0 yaobj->error = YAUID_ERROR_OPEN_LOCK_FILE;
303 0 return yaobj;
304 }
305
306 1 setbuf(yaobj->h_lockfile, NULL);
307
308 1 yaobj->i_lockfile = fileno(yaobj->h_lockfile);
309 }
310
311 1 return yaobj;
312 }
313  
314 1 void yauid_destroy(yauid* yaobj)
315 {
316 1 ▶ if(yaobj == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(yaobj == NULL) 0 1 1
317 0 return;
318
319 1 ▶ if(yaobj->h_lockfile)
Branch: 1 branch
BranchTrueFalseTotal
if(yaobj->h_lockfile) 1 0 1
320 1 fclose(yaobj->h_lockfile);
321
322 1 free(yaobj);
323 }
324  
325 0 char * yauid_get_error_text_by_code(enum yauid_status error)
326 {
327 0 ▶ if((YAUID_ERROR_CREATE_OBJECT - YAUID_OK) < error)
Branch: 1 branch
BranchTrueFalseTotal
if((YAUID_ERROR_CREATE_OBJECT - YAUID_OK) < error) 0 0 0
328 0 return NULL;
329
330 0 return error_text[error];
331 }
332  
333 1 void yauid_set_node_id(yauid* yaobj, unsigned long node_id)
334 {
335 1 yaobj->error = YAUID_OK;
336
337 1 ▶ if(node_id < LIMIT_MIN_NODE_ID)
Branch: 1 branch
BranchTrueFalseTotal
if(node_id < LIMIT_MIN_NODE_ID) 0 1 1
338 0 yaobj->error = YAUID_ERROR_SHORT_NODE_ID;
339 1 ▶ else if(node_id > NUMBER_LIMIT_NODE)
Branch: 1 branch
BranchTrueFalseTotal
else if(node_id > NUMBER_LIMIT_NODE) 0 1 1
340 0 yaobj->error = YAUID_ERROR_LONG_NODE_ID;
341 else
342 1 yaobj->node_id = node_id;
343 1 }
344  
345 1 void yauid_set_sleep_usec(yauid* yaobj, useconds_t sleep_usec)
346 {
347 1 yaobj->error = YAUID_OK;
348 1 yaobj->sleep_usec = sleep_usec;
349 1 }
350  
351 1 void yauid_set_try_count(yauid* yaobj, unsigned int try_count)
352 {
353 1 yaobj->error = YAUID_OK;
354 1 yaobj->try_count = try_count;
355 1 }
356  
357 0 time_t yauid_datetime_to_timestamp(const char *datetime)
358 {
359 struct tm tm;
360 time_t epoch;
361
362 0 ▶ if(strptime(datetime, "%Y-%m-%d %H:%M:%S", &tm) != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(strptime(datetime, "%Y-%m-%d %H:%M:%S", &tm) != NULL) 0 0 0
363 0 epoch = mktime(&tm);
364 else
365 0 epoch = (time_t)(0);
366
367 0 return epoch;
368 }
369  
370 0 void yauid_get_period_key_by_datetime(const char *from_datetime,
371 const char *to_datetime,
372 unsigned long long int from_node_id,
373 unsigned long long int to_node_id,
374 struct yauid_period_key *pkey)
375 {
376 0 ▶ if(to_datetime == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(to_datetime == NULL) 0 0 0
377 0 to_datetime = from_datetime;
378
379 0 yauid_get_period_key_by_timestamp(yauid_datetime_to_timestamp(from_datetime),
380 yauid_datetime_to_timestamp(to_datetime),
381 from_node_id, to_node_id,
382 pkey);
383 0 }
384  
385 0 void yauid_get_period_key_by_timestamp(time_t from_timestamp,
386 time_t to_timestamp,
387 unsigned long long int from_node_id,
388 unsigned long long int to_node_id,
389 struct yauid_period_key *pkey)
390 {
391 0 ▶ if(pkey == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(pkey == NULL) 0 0 0
392 0 return;
393
394 0 pkey->max = 0;
395 0 pkey->min = 0;
396
397 0 ▶ if(to_timestamp == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(to_timestamp == 0) 0 0 0
398 0 to_timestamp = from_timestamp;
399
400 0 ▶ if(from_node_id == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(from_node_id == 0) 0 0 0
401 0 from_node_id = 1;
402
403 0 ▶ if(to_node_id == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(to_node_id == 0) 0 0 0
404 0 to_node_id = NUMBER_LIMIT_NODE;
405
406 0 pkey->min = (hkey_t)(from_timestamp);
407 0 ▶ if(pkey->min == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(pkey->min == 0) 0 0 0
408 0 return;
409
410 0 pkey->min <<= BIT_LIMIT_NODE;
411
412 0 pkey->min |= (hkey_t)(from_node_id);
413 0 pkey->min <<= BIT_LIMIT_INC;
414
415 0 pkey->min |= (hkey_t)(1);
416
417 0 pkey->max = (hkey_t)(to_timestamp);
418 0 ▶ if(pkey->max == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(pkey->max == 0) 0 0 0
419 0 return;
420
421 0 pkey->max <<= BIT_LIMIT_NODE;
422
423 0 pkey->max |= (hkey_t)(to_node_id);
424 0 pkey->max <<= BIT_LIMIT_INC;
425
426 0 pkey->max |= (hkey_t)(NUMBER_LIMIT);
427 }
428  
429 #endif
430  
431  
432 typedef yauid * Number__YAUID;
433  
434 MODULE = Number::YAUID PACKAGE = Number::YAUID
435  
436 PROTOTYPES: DISABLE
437  
438 Number::YAUID
439 init(perl_class, filepath_key, filepath_node_id)
440 char *perl_class;
441 SV *filepath_key;
442 SV *filepath_node_id;
443
444 CODE:
445 1 ▶ if(SvOK(filepath_key) && SvOK(filepath_node_id))
Branch: 2 branches
BranchTrueFalseTotal
if(SvOK(filepath_key) && SvOK(filepath_node_id)) 1 0 1
if(SvOK(filepath_key) && SvOK(filepath_node_id)) 0 1 1
446 {
447 0 ▶ RETVAL = yauid_init((char *)SvPV_nolen(filepath_key), (char *)SvPV_nolen(filepath_node_id));
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = yauid_init((char *)SvPV_nolen(filepath_key), (char *)SvPV_nolen(filepath_node_id)); 0 0 0
448 }
449 1 ▶ else if(SvOK(filepath_key))
Branch: 1 branch
BranchTrueFalseTotal
else if(SvOK(filepath_key)) 1 0 1
450 {
451 1 RETVAL = yauid_init((char *)SvPV_nolen(filepath_key), NULL);
452 }
453 else {
454 0 RETVAL = NULL;
455 }
456
457 OUTPUT:
458 RETVAL
459  
460 SV*
461 get_key(obj)
462 Number::YAUID obj;
463
464 CODE:
465 1000 RETVAL = newSViv(yauid_get_key(obj));
466
467 OUTPUT:
468 RETVAL
469  
470 SV*
471 get_key_once(obj)
472 Number::YAUID obj;
473
474 CODE:
475 0 RETVAL = newSViv(yauid_get_key_once(obj));
476
477 OUTPUT:
478 RETVAL
479  
480 SV*
481 get_period_key_by_datetime(from_date = 0, to_date = 0, from_node = 0, to_node = 0)
482 char* from_date;
483 char* to_date;
484 unsigned long from_node;
485 unsigned long to_node;
486
487 CODE:
488 0 struct yauid_period_key pkey = {0};
489 0 yauid_get_period_key_by_datetime((const char *)(from_date), (const char *)(to_date),
490 (unsigned long long int)(from_node), (unsigned long long int)(to_node), &pkey);
491
492 0 AV *res = newAV();
493 0 av_push(res, newSViv(pkey.min));
494 0 av_push(res, newSViv(pkey.max));
495
496 0 RETVAL = newRV_noinc((SV*)res);
497
498 OUTPUT:
499 RETVAL
500  
501 SV*
502 get_period_key_by_timestamp(from_date = 0, to_date = 0, from_node = 0, to_node = 0)
503 unsigned long from_date;
504 unsigned long to_date;
505 unsigned long from_node;
506 unsigned long to_node;
507
508 CODE:
509 0 struct yauid_period_key pkey = {0};
510 0 yauid_get_period_key_by_timestamp((time_t)(from_date), (time_t)(to_date),
511 (unsigned long long int)(from_node), (unsigned long long int)(to_node), &pkey);
512
513 0 AV *res = newAV();
514 0 av_push(res, newSViv(pkey.min));
515 0 av_push(res, newSViv(pkey.max));
516
517 0 RETVAL = newRV_noinc((SV*)res);
518
519 OUTPUT:
520 RETVAL
521  
522 void
523 DESTROY(obj)
524 Number::YAUID obj;
525
526 CODE:
527 1 yauid_destroy(obj);
528  
529 SV*
530 get_error_text_by_code(error_id)
531 int error_id;
532
533 CODE:
534 0 char * text = yauid_get_error_text_by_code((enum yauid_status)(error_id));
535 0 ▶ if(text)
Branch: 1 branch
BranchTrueFalseTotal
if(text) 0 0 0
536 {
537 0 RETVAL = newSVpv(text, 0);
538 }
539 else {
540 0 RETVAL = &PL_sv_undef;
541 }
542
543 OUTPUT:
544 RETVAL
545  
546 SV*
547 get_error_code(obj)
548 Number::YAUID obj;
549
550 CODE:
551 1 RETVAL = newSViv(obj->error);
552 OUTPUT:
553 RETVAL
554  
555 SV*
556 set_node_id(obj, node_id)
557 Number::YAUID obj;
558 unsigned long node_id;
559
560 CODE:
561 1 yauid_set_node_id(obj, node_id);
562
563 1 RETVAL = newSViv(YAUID_OK);
564 OUTPUT:
565 RETVAL
566  
567 SV*
568 set_sleep_usec(obj, sleep_usec = 35000)
569 Number::YAUID obj;
570 size_t sleep_usec;
571
572 CODE:
573 1 yauid_set_sleep_usec(obj, (useconds_t)(sleep_usec));
574
575 1 RETVAL = newSViv(YAUID_OK);
576 OUTPUT:
577 RETVAL
578  
579 SV*
580 set_try_count(obj, try_count = 0)
581 Number::YAUID obj;
582 unsigned int try_count;
583
584 CODE:
585 1 yauid_set_try_count(obj, try_count);
586
587 1 RETVAL = newSViv(YAUID_OK);
588 OUTPUT:
589 RETVAL
590  
591 SV*
592 get_timestamp_by_key(obj, hkey)
593 Number::YAUID obj;
594 SV* hkey;
595
596 CODE:
597 0 RETVAL = newSViv( yauid_get_timestamp( (hkey_t)(SvIV(hkey)) ) );
598 OUTPUT:
599 RETVAL
600  
601 SV*
602 get_node_id_by_key(obj, hkey = 0)
603 Number::YAUID obj;
604 SV* hkey;
605
606 CODE:
607 0 RETVAL = newSViv( yauid_get_node_id( (hkey_t)(SvIV(hkey)) ) );
608 OUTPUT:
609 RETVAL
610  
611 SV*
612 get_inc_id_by_key(obj, hkey = 0)
613 Number::YAUID obj;
614 SV* hkey;
615
616 CODE:
617 0 RETVAL = newSViv( yauid_get_inc_id( (hkey_t)(SvIV(hkey)) ) );
618 OUTPUT:
619 RETVAL
620  
621 SV*
622 get_max_inc()
623 CODE:
624 0 RETVAL = newSViv( yauid_get_max_inc() );
625 OUTPUT:
626 RETVAL
627  
628 SV*
629 get_max_node_id()
630 CODE:
631 0 RETVAL = newSViv( yauid_get_max_node_id() );
632 OUTPUT:
633 RETVAL
634  
635 SV*
636 get_max_timestamp()
637 CODE:
638 0 RETVAL = newSViv( yauid_get_max_timestamp() );
639 OUTPUT:
640 RETVAL
641  
642  
643  
644 SV*
645 YAUID_ERROR_CREATE_OBJECT()
646 CODE:
647 0 RETVAL = newSViv( YAUID_ERROR_CREATE_OBJECT );
648 OUTPUT:
649 RETVAL
650  
651  
« blib/lib/Number/YAUID.pm ↑ Summary