[asterisk-commits] russell: branch russell/parking_updates r114627 - /team/russell/parking_updat...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Apr 24 15:10:13 CDT 2008
Author: russell
Date: Thu Apr 24 15:10:11 2008
New Revision: 114627
URL: http://svn.digium.com/view/asterisk?view=rev&rev=114627
Log:
Add an option to randomize selection of the parking spot instead of using the
first one available. That's right, no more cherry picking 701 Mr. Sales guy!
Modified:
team/russell/parking_updates/main/features.c
Modified: team/russell/parking_updates/main/features.c
URL: http://svn.digium.com/view/asterisk/team/russell/parking_updates/main/features.c?view=diff&rev=114627&r1=114626&r2=114627
==============================================================================
--- team/russell/parking_updates/main/features.c (original)
+++ team/russell/parking_updates/main/features.c Thu Apr 24 15:10:11 2008
@@ -424,7 +424,8 @@
}
enum park_call_options {
- PARK_OPT_RINGING = (1 << 0),
+ PARK_OPT_RINGING = (1 << 0),
+ PARK_OPT_RANDOMIZE = (1 << 1),
};
struct park_call_args {
@@ -441,7 +442,7 @@
/* Park a call */
static int park_call_full(struct ast_channel *chan, struct ast_channel *peer, struct park_call_args *args)
{
- struct parkeduser *pu, *cur;
+ struct parkeduser *pu;
int i, x = -1, parking_range;
struct ast_context *con;
const char *parkinglotname;
@@ -482,19 +483,36 @@
ast_copy_string(pu->parkingexten, parkingexten, sizeof(pu->parkingexten));
x = atoi(parkingexten);
} else {
+ int start;
+ struct parkeduser *cur = NULL;
+
/* Select parking space within range */
- parking_range = args->parkinglot->parking_stop - args->parkinglot->parking_start+1;
- for (i = 0; i < parking_range; i++) {
- x = (i + args->parkinglot->parking_offset) % parking_range + args->parkinglot->parking_start;
+ parking_range = args->parkinglot->parking_stop - args->parkinglot->parking_start + 1;
+
+ if (ast_test_flag(args, PARK_OPT_RANDOMIZE)) {
+ start = ast_random() % (args->parkinglot->parking_stop - args->parkinglot->parking_start + 1);
+ } else {
+ start = args->parkinglot->parking_start;
+ }
+
+ for (i = start; 1; i++) {
+ if (i == args->parkinglot->parking_stop + 1) {
+ i = args->parkinglot->parking_start - 1;
+ continue;
+ }
+
AST_LIST_TRAVERSE(&args->parkinglot->parkings, cur, list) {
- if (cur->parkingnum == x)
+ if (cur->parkingnum == i) {
break;
+ }
}
- if (!cur)
+
+ if (!cur || i == start - 1) {
break;
- }
-
- if (!(i < parking_range)) {
+ }
+ }
+
+ if (i == start - 1 && cur) {
ast_log(LOG_WARNING, "No more parking spaces\n");
ast_free(pu);
AST_LIST_UNLOCK(&args->parkinglot->parkings);
More information about the asterisk-commits
mailing list