GENIIISOFT-4607-v2.patch
1
===== apps/jukeui/src/jukefsm.c 1.238 vs edited =====
2
--- 1.238/apps/jukeui/src/jukefsm.c	2019-02-01 16:02:49 -05:00
3
+++ edited/apps/jukeui/src/jukefsm.c	2019-02-12 10:50:37 -05:00
4
@@ -46,6 +46,9 @@
5
 #define REDEEM_FLASH_PATH_ES   "/usr/local/touchtunes/etc/TT_PromoCode_SP_gen3pl_prod_v1_3.swf"
6
 #define REDEEM_FLASH_PATH_FR   "/usr/local/touchtunes/etc/TT_PromoCode_FR_gen3pl_prod_v2_8.swf"
7
 
8
+#define DEFAULT_BASECOST 1
9
+
10
+/* #define DEBUG */
11
 
12
 static jk_master JM = { 0 };
13
 jk_master *get_jk_master(){ return &JM; }
14
@@ -1221,76 +1224,34 @@
15
     TT_Type_PlayNow,                    // Play Now
16
 };
17
 
18
-typedef struct
19
-{
20
-    gint type;
21
-    gint value;
22
-} typevaluestruct;
23
-
24
 void
25
 enqueue_linked_song(gpointer data)
26
 {
27
     jk_master *jm  = get_jk_master();
28
-    tc_master *tcm = get_tc_master();
29
-    ConsumeType consume_type = 0;
30
-    Subject *subject ;
31
-    consume_credits_struct *cc = NULL;
32
-    guint basecost = 1;
33
-    WalletConsumeInfo consume_info;
34
-    gint playnow_surcharge = compute_playnow_surcharge();
35
-    
36
-    tracep ("Called");
37
-    // All this should happen only in a remote mode
38
-    if(test_juke_mode(JMODE_REMOTE)) {
39
-        // First off, figure out where the song comes from and how much it will cost.
40
-        if(jm->selected_in_tunecentral)
41
-            basecost = jm->selected_song->temp&~DOWNLOAD_BIT;
42
-        
43
-        //Include HomePromo pricing check into remote consume cost evaluation.
44
-        if(tcm->is_promo_song) {
45
-            g_print("enqueue_linked_song(): featured song pricing (base:%d)\n",basecost);
46
-            consume_type = jm->priority_queue?CONSUME_HOMEPROMO_PLAYNOW:CONSUME_HOMEPROMO;
47
-        } else if(tcm->is_recommendation && tcm->recom) {
48
-            gint pricing = tcm->recom->banner_to_recom?tcm->recom->banner_to_recom_pricing:tcm->recom->pricing;
49
+    ConsumeType consume_type;
50
+    Subject *subject;
51
+    consume_credits_struct cc = { 0, };
52
+    WalletConsumeInfo consume_info = { 0, };
53
+    guint credit_amount[WALLET_CREDIT_SOURCE_SIZE] = { 0, };
54
+    guint credit_total;
55
+
56
+    if (!test_juke_mode(JMODE_REMOTE)) {
57
+        return;
58
+    }
59
+
60
+    credit_total = jukefsm_compute_wallet_transaction(credit_amount, &consume_type);
61
+
62
+    if (wallet_get_price_and_coinage(jm->wallet, consume_type, credit_total, &consume_info)) {
63
+        g_warning(G_STRLOC ": wallet_get_price_and_coinage failed");
64
+        return;
65
+    }
66
 
67
-            if(pricing == PRICING_NORMAL) basecost = 1;
68
-            else if (pricing >= PRICING_FLAT) basecost = pricing;
69
-            else if (pricing == PRICING_BEST && tcm->recom->on_hd == 1) {
70
-                basecost = 1;
71
-            }
72
-            
73
-            if(basecost>1) // cost before playnow surcharge
74
-                consume_type = jm->priority_queue?CONSUME_TC_PLAYNOW:CONSUME_TC;
75
-            else
76
-                consume_type = jm->priority_queue?CONSUME_PLAYNOW:CONSUME_PLAY;
77
-        } else {
78
-            if(basecost > 1) {
79
-                consume_type = jm->priority_queue?CONSUME_TC_PLAYNOW:CONSUME_TC;
80
-            } else {
81
-                consume_type = jm->priority_queue?CONSUME_PLAYNOW:CONSUME_PLAY;
82
-            }
83
-        }
84
+    cc.credits = consume_info.nb_credits;
85
+    cc.cost    = consume_info.coinage;
86
+    strncpy(cc.device_id, jm->client_id, 63);
87
 
88
-        // Ok, we have the consume type. Inquire about the price.
89
-        if(tcm->is_promo_song?
90
-               wallet_get_price_and_coinage(WALLET(jm->wallet), consume_type, basecost+(jm->priority_queue?playnow_surcharge:0), &consume_info):
91
-               wallet_get_price_and_coinage(WALLET(jm->wallet), consume_type, 0, &consume_info)) {
92
-            //jm->client_cost = cost;    // 2 credits per play
93
-            //jm->client_money = money;   // 25 cents
94
-            //jm->client_credits = credits; // 6 plays available
95
-            cc = g_new0(consume_credits_struct,1);
96
-            cc->credits = consume_info.nb_credits;
97
-            cc->cost    = consume_info.coinage;
98
-            cc->source  = 0;    // Don't care either
99
-            cc->type    = 0;    // ...yup, you guessed right
100
-            cc->song_id = 0;    // Ditto
101
-            strncpy(cc->device_id,jm->client_id,63);
102
-            
103
-            if((subject = chick_get_subject(DATA_CONSUME_LINKED_CREDIT)))
104
-                subject_data_set_data_size(SUBJECTDATA(subject), cc, sizeof(consume_credits_struct));
105
-            
106
-            g_free(cc);
107
-        }
108
+    if ((subject = chick_get_subject(DATA_CONSUME_LINKED_CREDIT))) {
109
+        subject_data_set_data_size(SUBJECTDATA(subject), &cc, sizeof(cc));
110
     }
111
 }
112
 
113
@@ -1360,429 +1321,410 @@
114
     } else { errorp("Failed to order song!"); }
115
 }
116
 
117
-
118
-void // reworked for use with queue_list
119
-enqueue_song(gpointer data)
120
+static void
121
+jukefsm_save_type_value(const gchar *subject_name, gint type, gint value)
122
 {
123
+    Subject *subject;
124
+    struct {
125
+        gint type;
126
+        gint value;
127
+    } tv;
128
 
129
-    jk_master *jm = get_jk_master();
130
-    ConsumeType consume_type = 0;
131
-    LoggerPlayLog *play_log = NULL;
132
-    WalletConsumeInfo consume_info;
133
-    tc_master *tcm = get_tc_master();
134
-    gint dl = 0, basecost = 1;
135
-    gint playnow_surcharge = compute_playnow_surcharge();
136
-    Subject *subject = NULL;
137
-    gchar *path = NULL;
138
-    MPElement element;
139
-    typevaluestruct *tv = NULL;
140
-    consume_credits_struct *cc = NULL;
141
-    LoggerMoneyLog *moneylog = NULL;
142
-    gint nbCredits = 1;
143
-    songlist_spec *spec = NULL;
144
-    time_t now = time(NULL);
145
-
146
-    tracep ("Called");
147
- 
148
-    g_print("enqueue_song() selected_song:%p selected_pl %p\n",jm->selected_song,tcm->selected_playlist);
149
-    //if(time(NULL)%2==0) jm->selected_song->uniq_id = 35682201;
150
-    if(jm->selected_song->temp&DOWNLOAD_BIT) {
151
-        gchar songID[16] = {0};
152
-        dl = 1;
153
-        // download is made here now
154
-        g_snprintf(songID, sizeof(songID), "%d", jm->selected_song->son_id);
155
-        subject = chick_get_subject(jm->priority_queue?DATA_TELECOM_ORDER_SONG_NOW:
156
-                                    DATA_TELECOM_PURCHASE_SONG);
157
-        if(subject){
158
-            subject_data_set_data_as_string(SUBJECTDATA(subject), songID);
159
-            debugp("Asking telecom to download %s", songID);
160
-        } else { errorp("Failed to order song!"); }
161
-    }
162
-
163
-        // extract cost and download status
164
-    if(jm->selected_in_tunecentral) {
165
-        basecost = jm->selected_song->temp&~DOWNLOAD_BIT;
166
+    subject = chick_get_subject(subject_name);
167
+    if (!subject) {
168
+        g_warning(G_STRLOC ": Failed to get subject '%s'", subject_name);
169
+        return;
170
     }
171
-    if(jm->selected_song->is_multi_credit_song)
172
-        basecost = 1+jm->data.tunecentral_premium;
173
- 
174
-    if(tcm->is_promo_song) {
175
 
176
-        //GENIIISOFT-3009
177
-        //consume_type = jm->priority_queue?CONSUME_HOMEPROMO_PLAYNOW:CONSUME_HOMEPROMO;
178
-        if(basecost>1) // cost before playnow surcharge
179
-            consume_type = jm->priority_queue?CONSUME_TC_PLAYNOW:CONSUME_TC;
180
-        else
181
-            consume_type = jm->priority_queue?CONSUME_PLAYNOW:CONSUME_PLAY;
182
+    tv.type = type;
183
+    tv.value = value;
184
 
185
-     } else if(tcm->is_recommendation && tcm->recom) {
186
-        gint pricing = tcm->recom->banner_to_recom?tcm->recom->banner_to_recom_pricing:tcm->recom->pricing;
187
+    subject_data_set_data_size(SUBJECTDATA(subject), &tv, sizeof(tv));
188
+}
189
 
190
-        if(pricing == PRICING_NORMAL) basecost = 1;
191
-        else if(pricing >=PRICING_FLAT) basecost = pricing;
192
-        else if(pricing == PRICING_BEST && tcm->recom->on_hd == 1) {
193
-            basecost = 1;
194
-        }
195
+static void
196
+jukefsm_save_consume_info(const WalletConsumeInfo *consume_info)
197
+{
198
+    jukefsm_save_type_value(DATA_BOOKKEEP_SAVE_COINAGE, COINAGE_LINKED, consume_info->coinage);
199
+    jukefsm_save_type_value(DATA_BOOKKEEP_SAVE_CREDITS, CREDITS_PAID, consume_info->nb_credits);
200
+}
201
 
202
-        if(basecost>1) // cost before playnow surcharge
203
-            consume_type = jm->priority_queue?CONSUME_TC_PLAYNOW:CONSUME_TC;
204
-        else
205
-            consume_type = jm->priority_queue?CONSUME_PLAYNOW:CONSUME_PLAY;
206
+static void
207
+jukefsm_save_external_play(jk_master *jm, const WalletConsumeInfo *consume_info, const guint credit_amount[WALLET_CREDIT_SOURCE_SIZE])
208
+{
209
+    Subject *subject;
210
 
211
-//        g_print("enqueue_song(): recom song pricing (base:%d)\n",basecost);
212
-   } else {
213
-        jm->selected_song->temp = 0; // don't litter
214
-        // Determine the cost of this play
215
+    /* if we have a external unit (but not a playport since playport works just like jukebox) */
216
+    if (test_juke_mode(JMODE_REMOTE) && !test_juke_mode(JMODE_MONEY_MODE)) { 
217
+        /* if we have a merit counter top unit */
218
 
219
-        if(basecost>1) // cost before playnow surcharge
220
-            consume_type = jm->priority_queue?CONSUME_TC_PLAYNOW:CONSUME_TC;
221
-        else
222
-            consume_type = jm->priority_queue?CONSUME_PLAYNOW:CONSUME_PLAY;
223
-    }
224
+        if (!test_juke_mode(JMODE_CONSUME_BEFORE)) {
225
+            // We're definitely in a protocol 3 session. time to send consume credits
226
+            // messages to the meritd
227
+            consume_credits_struct cc = { 0, };
228
 
229
-    //Make sure not to divide by zero when calling wallet_consume_n_valued_credits below
230
-    if(jm->client_credits <= 0)
231
-        nbCredits = 1;
232
-    else
233
-        nbCredits = jm->client_credits;
234
-    
235
-    // Consume credits
236
-    if(jm->data.freemode ||
237
-       /* if we are remote, in consume before mode and not in mone mode, it means it's a JVL */
238
-      (test_juke_mode(JMODE_REMOTE) && test_juke_mode(JMODE_CONSUME_BEFORE) && !test_juke_mode(JMODE_MONEY_MODE) ?
239
-            wallet_consume_n_valued_credits(WALLET(jm->wallet),
240
-                                           JUKEUI_WALLET_SOURCE,
241
-                                           consume_type,
242
-                                           tcm->is_promo_song?basecost+(jm->priority_queue?playnow_surcharge:0):-1,
243
-                                           jm->client_money/nbCredits, //Divide money by credits to avoid sending the total list cost for each song queued...
244
-                                           &consume_info):
245
-            (tcm->is_promo_song?
246
-                wallet_consume_n_credits(WALLET(jm->wallet),
247
-                                        JUKEUI_WALLET_SOURCE,
248
-                                        consume_type,
249
-                                        basecost+(jm->priority_queue?playnow_surcharge:0),
250
-                                        &consume_info):
251
-                wallet_consume_credits(WALLET(jm->wallet),
252
-                                       JUKEUI_WALLET_SOURCE,
253
-                                       consume_type,
254
-                                       &consume_info)))) {
255
+            cc.credits = consume_info->nb_credits * wallet_get_cost(jm->wallet);
256
+            cc.cost    = consume_info->coinage;
257
+            cc.source  = credit_amount[WALLET_CREDIT_SOURCE_TUNECENTRAL] ? TT_Source_TC : TT_Source_ASI; /* Fixme: there is more that ASI possible if it's not TC */
258
+            cc.type    = jm->priority_queue ? TT_Type_PlayNow : TT_Type_Play;
259
+            cc.song_id = jm->selected_song->son_id;
260
+            strncpy(cc.device_id, jm->client_id, 63);
261
 
262
-        path = g_strdup_printf("%s/%08d.AE3", DEFAULT_MUSIC_PATH, jm->selected_song->uniq_id);
263
+            if ((subject = chick_get_subject(DATA_CONSUME_LINKED_CREDIT))) {
264
+                subject_data_set_data_size(SUBJECTDATA(subject), &cc, sizeof(cc));
265
+            }
266
 
267
-        // Add id, origin, interface info, etc.
268
-        play_log = logger_create_playlog();
269
-        play_log->song_id = jm->selected_song->son_id;
270
-        play_log->origin = jm->origin;
271
-        
272
-        /* Log the current content reference */
273
-        spec = (songlist_spec*)subject_data_get_data(SUBJECTDATA(chick_get_subject(XML_SONGLIST_LOCAL)));
274
-        if(spec){
275
-            memset(play_log->current_local_content_ref, 0, sizeof(play_log->current_local_content_ref));
276
-            strncpy(play_log->current_local_content_ref, spec->id, sizeof(play_log->current_local_content_ref)-1);
277
-        }
278
-        
279
+            /* From merit, do moneylog now */
280
+            if (!jm->data.freemode) {
281
+                LoggerMoneyLog moneylog = { 0, };
282
 
283
-        /* Log if the song is currently in the current content */
284
-        if(view_is_song_in_current_content(jm->selected_song->son_id))
285
-            play_log->song_is_in_local_content = TRUE;
286
-        else 
287
-            play_log->song_is_in_local_content = FALSE;
288
+                moneylog.origin = ORIGIN_MERIT3;
289
+                moneylog.rejected = FALSE;
290
+                moneylog.money_type = MONEY_EXTERN;  /* To be verified */
291
+                moneylog.money = consume_info->coinage;
292
+                moneylog.credit_type = 4;
293
+                moneylog.credits = consume_info->nb_credits;
294
 
295
-        
296
-        play_log->is_from_recom = tcm->is_recom_path;
297
+                if (jm->client_game_unit_id) {
298
+                    strncpy(moneylog.game_unit_id, jm->client_game_unit_id, sizeof(moneylog.game_unit_id) - 1);
299
+                }
300
+                if (jm->client_alt_game_unit_id) {
301
+                    strncpy(moneylog.alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(moneylog.alt_game_unit_id) - 1);
302
+                }
303
+                if (jm->client_id) {
304
+                    strncpy(moneylog.alt_game_unit_id_virt, jm->client_id, sizeof(moneylog.alt_game_unit_id_virt)-1);
305
+                }
306
 
307
-        // *** New client machine ids logging requirements ***
308
-        memset(play_log->game_unit_id, 0, sizeof(play_log->game_unit_id));
309
-        memset(play_log->alt_game_unit_id, 0, sizeof(play_log->alt_game_unit_id));
310
-        memset(play_log->alt_game_unit_id_virt, 0, sizeof(play_log->alt_game_unit_id_virt));
311
+                if ((subject = chick_get_subject(DATA_LOGGING_SAVE_MONEYLOG))) {
312
+                    subject_data_set_data_size(SUBJECTDATA(subject), &moneylog, sizeof(moneylog));
313
+                }
314
 
315
-        if(jm->client_game_unit_id != NULL)
316
-            strncpy(play_log->game_unit_id, jm->client_game_unit_id, sizeof(play_log->game_unit_id)-1);
317
+                jukefsm_save_consume_info(consume_info);
318
+            }                    
319
+        } else {
320
+            /* This is JVL's lair. Log the money entry here */
321
+            if (!jm->data.freemode) {
322
+                LoggerMoneyLog moneylog = { 0, };
323
 
324
-        if(jm->client_alt_game_unit_id != NULL)
325
-            strncpy(play_log->alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(play_log->alt_game_unit_id)-1);
326
+                moneylog.origin = jm->origin;
327
+                moneylog.rejected = FALSE;
328
+                moneylog.money_type = MONEY_EXTERN;  // To be verified
329
+                moneylog.money = jm->data.freemode ? 0 : consume_info->coinage;
330
+                moneylog.credit_type = 4;
331
+                moneylog.credits = consume_info->nb_credits;
332
 
333
-        if(jm->client_id != NULL) 
334
-            strncpy(play_log->alt_game_unit_id_virt, jm->client_id, sizeof(play_log->alt_game_unit_id_virt)-1);
335
-
336
-        //****************************************************
337
+                if (jm->client_game_unit_id) {
338
+                    strncpy(moneylog.game_unit_id, jm->client_game_unit_id, sizeof(moneylog.game_unit_id) - 1);
339
+                }
340
+                if (jm->client_alt_game_unit_id) {
341
+                    strncpy(moneylog.alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(moneylog.alt_game_unit_id) - 1);
342
+                }
343
+                if (jm->client_id) {
344
+                    strncpy(moneylog.alt_game_unit_id_virt, jm->client_id, sizeof(moneylog.alt_game_unit_id_virt) - 1);
345
+                }
346
 
347
-        play_log->interface = jm->iface;
348
-        
349
-        if(play_log->interface == JUKE_INVENTORY) {
350
-            if(tcm->is_promo_song){
351
-                inventory *inv = bruce_get_inv(JM.clicked_inventory);
352
-                if(inv && inv->current_ad_media){
353
-                    ad_manager_call_post_click_play(inv->current_ad_media, jm->selected_song, consume_info.coinage);
354
+                if ((subject = chick_get_subject(DATA_LOGGING_SAVE_MONEYLOG))) {
355
+                    subject_data_set_data_size(SUBJECTDATA(subject), &moneylog, sizeof(moneylog));
356
                 }
357
+
358
+                jukefsm_save_consume_info(consume_info);
359
             }
360
         }
361
-        
362
-        play_log->is_playnow = jm->priority_queue;
363
-        play_log->user_id = mytt_get_current_user_id();
364
-        
365
-        if(jm->data.freemode) {
366
-            play_log->is_freemode = TRUE;
367
-            play_log->credits = 0;
368
-            play_log->coinage = 0;
369
-            memset(play_log->credits_type, 0, sizeof(play_log->credits_type));
370
-        } else {
371
-            play_log->is_freemode = FALSE;
372
-            play_log->credits = consume_info.nb_credits;
373
-            play_log->coinage = consume_info.coinage;
374
-            memcpy(play_log->credits_type,consume_info.credits_type,
375
-                   sizeof(play_log->credits_type));
376
+    } else if (test_juke_mode(JMODE_REMOTE)) {
377
+        /* This is PLAYPORTT zone */
378
+        if (!jm->data.freemode) {
379
+            LoggerMoneyLog moneylog = { 0, };
380
+
381
+            moneylog.origin = jm->origin;
382
+            moneylog.rejected = FALSE;
383
+            moneylog.money_type = MONEY_EXTERN;  /* To be verified */
384
+            moneylog.money = consume_info->coinage;
385
+            moneylog.credit_type = 4;
386
+            moneylog.credits = consume_info->nb_credits;
387
+
388
+            if (jm->client_game_unit_id) {
389
+                strncpy(moneylog.game_unit_id, jm->client_game_unit_id, sizeof(moneylog.game_unit_id) - 1);
390
+            }
391
+            if (jm->client_alt_game_unit_id) {
392
+                strncpy(moneylog.alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(moneylog.alt_game_unit_id) - 1);
393
+            }
394
+            if (jm->client_id) {
395
+                strncpy(moneylog.alt_game_unit_id_virt, jm->client_id, sizeof(moneylog.alt_game_unit_id_virt) - 1);
396
+            }
397
+
398
+            if ((subject = chick_get_subject(DATA_LOGGING_SAVE_MONEYLOG))) {
399
+                subject_data_set_data_size(SUBJECTDATA(subject), &moneylog, sizeof(moneylog));
400
+            }
401
+
402
+            jukefsm_save_consume_info(consume_info);
403
         }
404
+    }
405
+}
406
+
407
+static guint
408
+jukefsm_sum_array(const guint *array, gsize n)
409
+{
410
+    guint sum = 0;
411
+    gsize i;
412
 
413
-        play_log->play_type = tcm->is_promo_song ? PLAYTYPE_HOMEPROMO :
414
-                                                dl ? PLAYTYPE_DOWNLOADED :
415
-                                    (basecost==1) ? PLAYTYPE_PLAY : PLAYTYPE_PLAY_TC;
416
+    for (i = 0; i < n; i++) {
417
+        /* XXX: Check overflow... */
418
+        sum += array[i];
419
+    }
420
+
421
+    return sum;
422
+}
423
+
424
+static void
425
+jukefsm_print_wallet_transaction(const guint credit_amount[WALLET_CREDIT_SOURCE_SIZE], ConsumeType consume_type)
426
+{
427
+#ifdef DEBUG
428
+    static const gchar *consume_names[] = {
429
+        [ CONSUME_PLAY ] = "play",
430
+        [ CONSUME_PLAYNOW ] = "playnow",
431
+        [ CONSUME_TC ] = "tc",
432
+        [ CONSUME_TC_PLAYNOW ] = "tc-playnow",
433
+        [ CONSUME_LINKED_PLAY ] = "linked-play",
434
+        [ CONSUME_LINKED_PLAYNOW ] = "linked-playnow",
435
+        [ CONSUME_SMS ] = "sms",
436
+        [ CONSUME_CUSTOM ] = "custom",
437
+        [ CONSUME_THIRD_PARTY ] = "third-party",
438
+    };
439
+    static const gchar *credit_source_names[] = {
440
+        [ WALLET_CREDIT_SOURCE_BASE ] = "base",
441
+        [ WALLET_CREDIT_SOURCE_TUNECENTRAL ] "tunecentral",
442
+        [ WALLET_CREDIT_SOURCE_BANNER ] = "banner",
443
+        [ WALLET_CREDIT_SOURCE_PLAYNOW ] = "playnow",
444
+        [ WALLET_CREDIT_SOURCE_THIRD_PARTY ] = "third-party",
445
+    };
446
+    GString *info;
447
+    gsize i;
448
 
449
-        play_log->is_downloaded = dl?TRUE:FALSE;
450
+    G_STATIC_ASSERT(G_N_ELEMENTS(consume_names) == CONSUME_SIZE);
451
+    G_STATIC_ASSERT(G_N_ELEMENTS(credit_source_names) == WALLET_CREDIT_SOURCE_SIZE);
452
 
453
-        if(jm->iface == TC_GENRES || jm->iface == TC_THEMES) {
454
-            play_log->songlist_id = tcm->genre_theme_id;
455
-        } else if(tcm->selected_playlist &&
456
-                  ((tcm->selected_song_in_playlist &&
457
-                    (jm->iface == MYTT_PUBLIC || jm->iface == MYTT_PRIVATE)) ||
458
-                   jm->iface == MYTT_PUBLIC_PLAYALL ||
459
-                   jm->iface == MYTT_PRIVATE_PLAYALL)) {
460
-            play_log->songlist_id = tcm->selected_playlist->id;
461
-        } else if(tcm->is_recommendation) {
462
-            play_log->interface = JUKE_RECOMMENDED;
463
-            //tcm->is_recommendation = 0; // cleared at is_recom_broken to avoid recommendation cascades
464
-            if(jm->selected_song->flag&SONG_ENTRY_FLAG_ALBUM_RECOM) play_log->songlist_id = 1;
465
-            else if(jm->selected_song->flag&SONG_ENTRY_FLAG_STYLE_RECOM) play_log->songlist_id = 2;
466
+    info = g_string_new("Wallet transaction: Credit sources:");
467
 
468
+    for (i = 0; i < WALLET_CREDIT_SOURCE_SIZE; i++) {
469
+        if (credit_amount[i]) {
470
+            g_string_append_printf(info, " %s=%u", credit_source_names[i], credit_amount[i]);
471
         }
472
+    }
473
 
474
-        // Final step : play journal
475
-        journal_insert_play(jm->selected_song->son_id,(basecost>1)?J_PLAY_TC:J_PLAY_NORMAL);
476
-        if(jm->oldest_playtime_in_session == 0) jm->oldest_playtime_in_session = now;
477
+    g_string_append_printf(info, " total=%u", jukefsm_sum_array(credit_amount, WALLET_CREDIT_SOURCE_SIZE));
478
+    g_string_append_printf(info, " Consume type: %s", consume_names[consume_type]);
479
 
480
-        /* Queue song element */
481
-        memset(&element, 0, sizeof(MPElement));
482
-        element.uid = jm->selected_song->uniq_id;
483
-        element.sid = jm->selected_song->son_id;
484
-        strncpy(element.path, path, strlen(path));
485
-        element.priority = jm->priority_queue? MP_QUEUE_PRIORITY_HIGH : MP_QUEUE_PRIORITY_NORMAL;
486
-        element.type = MP_ELEMENT_MUSIC;
487
-        element.available = dl?FALSE:TRUE;
488
-        memcpy(&element.play_log, play_log, sizeof(element.play_log));
489
-        element.log_element = TRUE;        // Yes, write this log
490
-        element.play_log.overplays = 0;
491
-        element.timestamp = now;
492
-        subject = chick_get_subject(DATA_QUEUE_SONG_ELEMENT);
493
-        subject_data_set_data_size(SUBJECTDATA(subject), &element, sizeof(element));
494
+    g_print("%s\n", info->str);
495
 
496
-        //
497
-        // Special treatment for external unit that queued songs 
498
-        //
499
-        //
500
-        
501
-        // if we have a external unit (but not a playport since playport works just like jukebox)        
502
-        if(test_juke_mode(JMODE_REMOTE) && !test_juke_mode(JMODE_MONEY_MODE)) { 
503
+    g_string_free(info, TRUE);
504
+#endif /* DEBUG */
505
+}
506
 
507
-            // if we have a merit counter top unit 
508
-            if(!test_juke_mode(JMODE_CONSUME_BEFORE)) {
509
-                // We're definitely in a protocol 3 session. time to send consume credits
510
-                // messages to the meritd
511
+guint
512
+jukefsm_compute_wallet_transaction(guint credit_amount[WALLET_CREDIT_SOURCE_SIZE], ConsumeType *consume_type)
513
+{
514
+    jk_master *jm = get_jk_master();
515
+    tc_master *tcm = get_tc_master();
516
+    guint basecost = DEFAULT_BASECOST;
517
 
518
+    g_return_val_if_fail(credit_amount, 0);
519
+    g_return_val_if_fail(consume_type, 0);
520
 
521
-                cc = g_new0(consume_credits_struct,1);
522
-                cc->credits = consume_info.nb_credits * wallet_get_cost(WALLET(jm->wallet));
523
-                cc->cost    = consume_info.coinage;
524
-                cc->source  = (basecost>1)?TT_Source_TC:TT_Source_ASI; // Fixme: there is more that ASI possible if it's not TC
525
-                cc->type    = jm->priority_queue?TT_Type_PlayNow:TT_Type_Play;
526
-                cc->song_id = jm->selected_song->son_id;
527
-                strncpy(cc->device_id,jm->client_id,63);
528
-                g_print("Merit : Gonna depop credits:%u cost:%u for song %u\n",cc->credits, cc->cost, cc->song_id);
529
-                if((subject = chick_get_subject(DATA_CONSUME_LINKED_CREDIT)))
530
-                    subject_data_set_data_size(SUBJECTDATA(subject), cc, sizeof(consume_credits_struct));
531
-                g_free(cc);
532
+    credit_amount[WALLET_CREDIT_SOURCE_BASE] = DEFAULT_BASECOST;
533
 
534
-                //
535
-                // Ok, from merit, do moneylog now
536
-                //
537
-                if(!(jm->data.freemode))
538
-                {
539
-                    moneylog = g_new0(LoggerMoneyLog, 1);
540
-                    moneylog->origin = ORIGIN_MERIT3;
541
-                    moneylog->rejected = FALSE;
542
-                    moneylog->money_type = MONEY_EXTERN;  // To be verified
543
-                    moneylog->money = consume_info.coinage;
544
-                    moneylog->credit_type = 4;
545
-                    moneylog->credits = consume_info.nb_credits;
546
-                    
547
-                    // *** New client machine ids logging requirements ***
548
-                    if(jm->client_game_unit_id != NULL)
549
-                        strncpy(moneylog->game_unit_id, jm->client_game_unit_id, sizeof(moneylog->game_unit_id)-1);
550
+    if (jm->priority_queue) {
551
+        credit_amount[WALLET_CREDIT_SOURCE_PLAYNOW] = compute_playnow_surcharge();
552
+    }
553
 
554
-                    if(jm->client_alt_game_unit_id != NULL)
555
-                        strncpy(moneylog->alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(moneylog->alt_game_unit_id)-1);
556
+    if (jm->selected_in_tunecentral) {
557
+        basecost = credit_amount[WALLET_CREDIT_SOURCE_BASE] = jm->selected_song->temp & ~DOWNLOAD_BIT;
558
+    }
559
 
560
-                    if(jm->client_id != NULL)
561
-                        strncpy(moneylog->alt_game_unit_id_virt, jm->client_id, sizeof(moneylog->alt_game_unit_id_virt)-1);
562
+    if (jm->selected_song && jm->selected_song->is_multi_credit_song) {
563
+        basecost = DEFAULT_BASECOST + jm->data.tunecentral_premium;
564
 
565
-                    if((subject = chick_get_subject(DATA_LOGGING_SAVE_MONEYLOG)))
566
-                        subject_data_set_data_size(SUBJECTDATA(subject), moneylog, sizeof(LoggerMoneyLog));
567
-                    g_free(moneylog);
568
-                }
569
+        credit_amount[WALLET_CREDIT_SOURCE_TUNECENTRAL] = jm->data.tunecentral_premium;
570
+    }
571
 
572
+    if (!tcm->is_promo_song && tcm->is_recommendation && tcm->recom) {
573
+        gint pricing = tcm->recom->banner_to_recom ? tcm->recom->banner_to_recom_pricing : tcm->recom->pricing;
574
 
575
-                //
576
-                // Bookkeep the coinage
577
-                subject = chick_get_subject(DATA_BOOKKEEP_SAVE_COINAGE);
578
-                if(subject && !(jm->data.freemode)){
579
-                    tv = g_new0(typevaluestruct,1);
580
-                    tv->type = COINAGE_LINKED;
581
-                    tv->value = consume_info.coinage;
582
-                    subject_data_set_data_size(SUBJECTDATA(subject), tv, sizeof(typevaluestruct));
583
-                    g_free(tv);
584
-                }
585
+        if (tcm->recom->banner_to_recom) {
586
+            credit_amount[WALLET_CREDIT_SOURCE_BANNER] = tcm->recom->banner_to_recom_pricing;
587
+        }
588
 
589
-                //
590
-                // Bookkeep save credit used as paid credit
591
-                subject = chick_get_subject(DATA_BOOKKEEP_SAVE_CREDITS);
592
-                if(subject && !(jm->data.freemode)) {
593
-                    tv = g_new0(typevaluestruct,1);
594
-                    tv->type = CREDITS_PAID;
595
-                    tv->value = consume_info.nb_credits;
596
-                    subject_data_set_data_size(SUBJECTDATA(subject), tv, sizeof(typevaluestruct));
597
-                    g_free(tv);
598
-                }                    
599
+        if (pricing == PRICING_NORMAL) {
600
+            basecost = DEFAULT_BASECOST;
601
+        } else if (pricing >= PRICING_FLAT) {
602
+            basecost = pricing;
603
+        } else if (pricing == PRICING_BEST && tcm->recom->on_hd == 1) {
604
+            basecost = DEFAULT_BASECOST;
605
+        }
606
+    }
607
 
608
-            } else {
609
-                // This is JVL's lair. Log the money entry here
610
-                if(!(jm->data.freemode))
611
-                {
612
-                    moneylog = g_new0(LoggerMoneyLog, 1);
613
-                    moneylog->origin = jm->origin;
614
-                    moneylog->rejected = FALSE;
615
-                    moneylog->money_type = MONEY_EXTERN;  // To be verified
616
-                    moneylog->money = jm->data.freemode ? 0 : consume_info.coinage;
617
-                    moneylog->credit_type = 4;
618
-                    moneylog->credits = consume_info.nb_credits;
619
-                    
620
-                    // *** New client machine ids logging requirements ***
621
-                    if(jm->client_game_unit_id != NULL)
622
-                        strncpy(moneylog->game_unit_id, jm->client_game_unit_id, sizeof(moneylog->game_unit_id)-1);
623
+    if (basecost > 1) {
624
+        *consume_type = jm->priority_queue ? CONSUME_TC_PLAYNOW : CONSUME_TC;
625
+    } else {
626
+        *consume_type = jm->priority_queue ? CONSUME_PLAYNOW : CONSUME_PLAY;
627
+    }
628
 
629
-                    if(jm->client_alt_game_unit_id != NULL)
630
-                        strncpy(moneylog->alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(moneylog->alt_game_unit_id)-1);
631
+    jukefsm_print_wallet_transaction(credit_amount, *consume_type);
632
 
633
-                    if(jm->client_id != NULL)
634
-                        strncpy(moneylog->alt_game_unit_id_virt, jm->client_id, sizeof(moneylog->alt_game_unit_id_virt)-1);
635
+    return jukefsm_sum_array(credit_amount, WALLET_CREDIT_SOURCE_SIZE);
636
+}
637
 
638
-                    if((subject = chick_get_subject(DATA_LOGGING_SAVE_MONEYLOG)))
639
-                        subject_data_set_data_size(SUBJECTDATA(subject), moneylog, sizeof(LoggerMoneyLog));
640
-                    g_free(moneylog);
641
-                }
642
+void
643
+enqueue_song(gpointer unused)
644
+{
645
+    jk_master *jm = get_jk_master();
646
+    tc_master *tcm = get_tc_master();
647
+    ConsumeType consume_type;
648
+    WalletConsumeInfo consume_info = { 0, };
649
+    MPElement element = { 0, };
650
+    guint credit_amount[WALLET_CREDIT_SOURCE_SIZE] = { 0, };
651
+    guint credit_total;
652
+    gboolean dl = FALSE;
653
+    Subject *subject = NULL;
654
+    gchar *path = NULL;
655
+    songlist_spec *spec = NULL;
656
+    time_t now = time(NULL);
657
 
658
-                //
659
-                // Bookkeep the coinage
660
-                subject = chick_get_subject(DATA_BOOKKEEP_SAVE_COINAGE);
661
-                if(subject && !(jm->data.freemode)){
662
-                    tv = g_new0(typevaluestruct,1);
663
-                    tv->type = COINAGE_LINKED;
664
-                    tv->value = consume_info.coinage;
665
-                    subject_data_set_data_size(SUBJECTDATA(subject), tv, sizeof(typevaluestruct));
666
-                    g_free(tv);
667
-                }
668
+    if (jm->selected_song->temp & DOWNLOAD_BIT) {
669
+        gchar songID[16];
670
 
671
+        dl = TRUE;
672
 
673
-                //
674
-                // Bookkeep save credit used as paid credit
675
-                subject = chick_get_subject(DATA_BOOKKEEP_SAVE_CREDITS);
676
-                if(subject && !(jm->data.freemode)){
677
-                    tv = g_new0(typevaluestruct,1);
678
-                    tv->type = CREDITS_PAID;
679
-                    tv->value = consume_info.nb_credits;
680
-                    subject_data_set_data_size(SUBJECTDATA(subject), tv, sizeof(typevaluestruct));
681
-                    g_free(tv);
682
-                }
683
-            }
684
-        } else if(test_juke_mode(JMODE_REMOTE)) {
685
-            // This is PLAYPORTT test zone.........
686
-            if(!(jm->data.freemode))
687
-            {
688
-                moneylog = g_new0(LoggerMoneyLog, 1);
689
-                moneylog->origin = jm->origin;
690
-                moneylog->rejected = FALSE;
691
-                moneylog->money_type = MONEY_EXTERN;  // To be verified
692
-                moneylog->money = consume_info.coinage;
693
-                moneylog->credit_type = 4;
694
-                moneylog->credits = consume_info.nb_credits;
695
-                
696
-                // *** New client machine ids logging requirements ***
697
-                if(jm->client_game_unit_id != NULL)
698
-                    strncpy(moneylog->game_unit_id, jm->client_game_unit_id, sizeof(moneylog->game_unit_id)-1);
699
+        g_snprintf(songID, sizeof(songID), "%d", jm->selected_song->son_id);
700
+        subject = chick_get_subject(jm->priority_queue ? DATA_TELECOM_ORDER_SONG_NOW : DATA_TELECOM_PURCHASE_SONG);
701
+
702
+        if (subject) {
703
+            subject_data_set_data_as_string(SUBJECTDATA(subject), songID);
704
+        } else {
705
+            g_warning(G_STRLOC ": Failed to order song!");
706
+        }
707
+    }
708
+
709
+    credit_total = jukefsm_compute_wallet_transaction(credit_amount, &consume_type);
710
+
711
+    /* credit_total can be 0 in the case where an ad points to a free song */
712
+    if (!jm->data.freemode && credit_total) {
713
+        if (!wallet_consume_n_credits(jm->wallet, JUKEUI_WALLET_SOURCE, consume_type, credit_amount, &consume_info)) {
714
+            g_warning(G_STRLOC ": wallet_consume_n_credits failed");
715
+            return;
716
+        }
717
+    }
718
+
719
+    path = g_strdup_printf("%s/%08d.AE3", DEFAULT_MUSIC_PATH, jm->selected_song->uniq_id);
720
+
721
+    element.play_log.song_id = jm->selected_song->son_id;
722
+    element.play_log.origin = jm->origin;
723
+
724
+    spec = (songlist_spec *)subject_data_get_data(SUBJECTDATA(chick_get_subject(XML_SONGLIST_LOCAL)));
725
+    if (spec) {
726
+        memset(element.play_log.current_local_content_ref, 0, sizeof(element.play_log.current_local_content_ref));
727
+        strncpy(element.play_log.current_local_content_ref, spec->id, sizeof(element.play_log.current_local_content_ref) - 1);
728
+    } else {
729
+        g_warning(G_STRLOC ": Failed to get local song list");
730
+    }
731
 
732
-                if(jm->client_alt_game_unit_id != NULL)
733
-                    strncpy(moneylog->alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(moneylog->alt_game_unit_id)-1);
734
+    element.play_log.song_is_in_local_content = view_is_song_in_current_content(jm->selected_song->son_id) ? TRUE : FALSE;
735
+    element.play_log.is_from_recom = tcm->is_recom_path;
736
 
737
-                if(jm->client_id != NULL)
738
-                    strncpy(moneylog->alt_game_unit_id_virt, jm->client_id, sizeof(moneylog->alt_game_unit_id_virt)-1);
739
-                
740
-                if((subject = chick_get_subject(DATA_LOGGING_SAVE_MONEYLOG)))
741
-                    subject_data_set_data_size(SUBJECTDATA(subject), moneylog, sizeof(LoggerMoneyLog));
742
-                g_free(moneylog);
743
-            }
744
+    if (jm->client_game_unit_id) {
745
+        strncpy(element.play_log.game_unit_id, jm->client_game_unit_id, sizeof(element.play_log.game_unit_id) - 1);
746
+    }
747
+    if (jm->client_alt_game_unit_id) {
748
+        strncpy(element.play_log.alt_game_unit_id, jm->client_alt_game_unit_id, sizeof(element.play_log.alt_game_unit_id) - 1);
749
+    }
750
+    if (jm->client_id) {
751
+        strncpy(element.play_log.alt_game_unit_id_virt, jm->client_id, sizeof(element.play_log.alt_game_unit_id_virt) - 1);
752
+    }
753
 
754
-            //
755
-                // Bookkeep the coinage
756
-            subject = chick_get_subject(DATA_BOOKKEEP_SAVE_COINAGE);
757
-            if(subject && !(jm->data.freemode)){
758
-                tv = g_new0(typevaluestruct,1);
759
-                tv->type = COINAGE_LINKED;
760
-                tv->value = consume_info.coinage;
761
-                subject_data_set_data_size(SUBJECTDATA(subject), tv, sizeof(typevaluestruct));
762
-                g_free(tv);
763
-            }
764
+    element.play_log.interface = jm->iface;
765
 
766
+    if (element.play_log.interface == JUKE_INVENTORY && tcm->is_promo_song) {
767
+        inventory *inv = bruce_get_inv(JM.clicked_inventory);
768
 
769
-            //
770
-                // Bookkeep save credit used as paid credit
771
-            subject = chick_get_subject(DATA_BOOKKEEP_SAVE_CREDITS);
772
-            if(subject && !(jm->data.freemode)){
773
-                tv = g_new0(typevaluestruct,1);
774
-                tv->type = CREDITS_PAID;
775
-                tv->value = consume_info.nb_credits;
776
-                subject_data_set_data_size(SUBJECTDATA(subject), tv, sizeof(typevaluestruct));
777
-                g_free(tv);
778
-            }
779
+        if (inv && inv->current_ad_media) {
780
+            ad_manager_call_post_click_play(inv->current_ad_media, jm->selected_song, consume_info.coinage);
781
         }
782
+    }
783
 
784
-        if(play_log)
785
-            g_free(play_log);
786
-        if(path)
787
-            g_free(path);
788
+    element.play_log.is_playnow = jm->priority_queue;
789
+    element.play_log.user_id = mytt_get_current_user_id();
790
 
791
-        mytt_song_selection(jm->selected_song->son_id,
792
-                            tcm->selected_playlist?tcm->selected_playlist->id:-1,
793
-                            (basecost>1),
794
-                            jm->data.freemode ? 0:
795
-                            (basecost+(jm->priority_queue?playnow_surcharge:0)));
796
+    if (jm->data.freemode) {
797
+        element.play_log.is_freemode = TRUE;
798
+    } else {
799
+        element.play_log.credits = consume_info.nb_credits;
800
+        element.play_log.coinage = consume_info.coinage;
801
+        memcpy(element.play_log.credits_type, consume_info.credits_type, sizeof(element.play_log.credits_type));
802
+    }
803
+
804
+    element.play_log.play_type = tcm->is_promo_song ?
805
+        PLAYTYPE_HOMEPROMO : dl ? PLAYTYPE_DOWNLOADED : credit_amount[WALLET_CREDIT_SOURCE_TUNECENTRAL] ?
806
+        PLAYTYPE_PLAY_TC : PLAYTYPE_PLAY;
807
 
808
-        if(tcm->is_recom_path)
809
-        {
810
-            jm->ulog.play_song_id = jm->selected_song->son_id;
811
-            jukefsm_log_ui();
812
-            jm->ulog.play_song_id = 0;
813
+    element.play_log.is_downloaded = dl;
814
 
815
-            if(jm->iface == JUKE_RECOMMENDED) tcm->is_recom_path = FALSE;
816
+    if (jm->iface == TC_GENRES || jm->iface == TC_THEMES) {
817
+        element.play_log.songlist_id = tcm->genre_theme_id;
818
+    } else if (tcm->selected_playlist &&
819
+            ((tcm->selected_song_in_playlist &&
820
+              (jm->iface == MYTT_PUBLIC || jm->iface == MYTT_PRIVATE)) ||
821
+             jm->iface == MYTT_PUBLIC_PLAYALL ||
822
+             jm->iface == MYTT_PRIVATE_PLAYALL)) {
823
+        element.play_log.songlist_id = tcm->selected_playlist->id;
824
+    } else if (tcm->is_recommendation) {
825
+        element.play_log.interface = JUKE_RECOMMENDED;
826
+        
827
+        if (jm->selected_song->flag & SONG_ENTRY_FLAG_ALBUM_RECOM) {
828
+            element.play_log.songlist_id = 1;
829
+        } else if (jm->selected_song->flag & SONG_ENTRY_FLAG_STYLE_RECOM) {
830
+            element.play_log.songlist_id = 2;
831
         }
832
+    }
833
+
834
+    journal_insert_play(jm->selected_song->son_id, credit_amount[WALLET_CREDIT_SOURCE_TUNECENTRAL] ? J_PLAY_TC : J_PLAY_NORMAL);
835
+
836
+    if (!jm->oldest_playtime_in_session) {
837
+        jm->oldest_playtime_in_session = now;
838
+    }
839
+
840
+    element.uid = jm->selected_song->uniq_id;
841
+    element.sid = jm->selected_song->son_id;
842
+    strncpy(element.path, path, strlen(path));
843
+    element.priority = jm->priority_queue ? MP_QUEUE_PRIORITY_HIGH : MP_QUEUE_PRIORITY_NORMAL;
844
+    element.type = MP_ELEMENT_MUSIC;
845
+    element.available = dl ? FALSE : TRUE;
846
+    element.log_element = TRUE;
847
+    element.play_log.overplays = 0;
848
+    element.timestamp = now;
849
 
850
-        // Final step : play journal
851
-        //journal_insert_play(jm->selected_song->son_id,(basecost>1)?J_PLAY_TC:J_PLAY_NORMAL);
852
-        // refresh the jukebox popular genre
853
-        refresh_jukebox_popular_genre();
854
-        refresh_session_popular_genre(jm->oldest_playtime_in_session);
855
+    subject = chick_get_subject(DATA_QUEUE_SONG_ELEMENT);
856
+    subject_data_set_data_size(SUBJECTDATA(subject), &element, sizeof(element));
857
 
858
-        // for interlude
859
-        //jm->data.credits -= consume_info.nb_credits;
860
+    jukefsm_save_external_play(jm, &consume_info, credit_amount);
861
+
862
+    g_free(path);
863
+
864
+    mytt_song_selection(jm->selected_song->son_id,
865
+            tcm->selected_playlist ? tcm->selected_playlist->id : -1,
866
+            credit_amount[WALLET_CREDIT_SOURCE_TUNECENTRAL],
867
+            jm->data.freemode ? 0 : credit_total);
868
+
869
+    if (tcm->is_recom_path) {
870
+        jm->ulog.play_song_id = jm->selected_song->son_id;
871
+        jukefsm_log_ui();
872
+        jm->ulog.play_song_id = 0;
873
+
874
+        if (jm->iface == JUKE_RECOMMENDED) {
875
+            tcm->is_recom_path = FALSE;
876
+        }
877
     }
878
 
879
+    refresh_jukebox_popular_genre();
880
+    refresh_session_popular_genre(jm->oldest_playtime_in_session);
881
 }
882
 
883
 void
884
===== apps/jukeui/src/jukefsm.h 1.87 vs edited =====
885
--- 1.87/apps/jukeui/src/jukefsm.h	2019-02-01 16:02:49 -05:00
886
+++ edited/apps/jukeui/src/jukefsm.h	2019-02-12 10:39:32 -05:00
887
@@ -116,7 +116,7 @@
888
     gboolean reshuffle_rightside_recom;
889
     
890
     // engines
891
-    GObject *wallet;
892
+    Wallet *wallet;
893
     gpointer promoengine;
894
     // ccard transactions
895
     gchar transaction_id[64];
896
@@ -189,6 +189,7 @@
897
 gboolean jukefsm_set_bruce_screen(ad_manager_screen);
898
 void payment_confirmation_popup_show();
899
 
900
+guint jukefsm_compute_wallet_transaction(guint credit_amount[WALLET_CREDIT_SOURCE_SIZE], ConsumeType *consume_type);
901
 
902
 // defines for FSM events
903
 #define FSM_EVT_SCREEN_TOUCHED      "juke_screen_touch"
904
===== apps/jukeui/src/tcfsm.c 1.81 vs edited =====
905
--- 1.81/apps/jukeui/src/tcfsm.c	2019-02-01 16:02:49 -05:00
906
+++ edited/apps/jukeui/src/tcfsm.c	2019-02-12 10:37:20 -05:00
907
@@ -2068,81 +2068,70 @@
908
 queue_linked_list(gpointer data)
909
 {
910
     GList *p;
911
-    tc_master *tcm = (tc_master *)data;
912
+    tc_master *tcm = data;
913
     jk_master *jm = get_jk_master();
914
-    ConsumeType consume_type = 0;
915
-    Subject *subject ;
916
-    consume_credits_struct *cc = NULL;
917
-    guint basecost = 1;
918
-    WalletConsumeInfo consume_info;
919
-    guint  totalCredits = 0;
920
-    gfloat totalCoinage = 0;
921
-    gint partialQueue = 0;
922
+    Subject *subject;
923
+    consume_credits_struct cc = { 0, };
924
+    guint total_credits = 0;
925
+    guint total_coinage = 0;
926
+    gint partial_queue = 0;
927
 
928
-    if(!jm || !tcm) return;
929
+    g_return_if_fail(jm);
930
+    g_return_if_fail(tcm);
931
 
932
-    // move to play buttons
933
-    if(jm->iface == MYTT_PUBLIC) jm->iface = MYTT_PUBLIC_PLAYALL;
934
-    if(jm->iface == MYTT_PRIVATE) jm->iface = MYTT_PRIVATE_PLAYALL;
935
-    if(tcm->selected_playlist == NULL) {
936
-        errorp("queue linked list with no selected list");
937
+    /* move to play buttons */
938
+    if (jm->iface == MYTT_PUBLIC || jm->iface == MYTT_PRIVATE) {
939
+        jm->iface = MYTT_PUBLIC_PLAYALL;
940
+    }
941
+
942
+    if (!tcm->selected_playlist) {
943
+        g_warning(G_STRLOC ": queue linked list with no selected list");
944
         return;
945
     }
946
-    // loop and calculate cost for all songs
947
-    if(tcm->selected_playlist == &tcm->mytt_entry) {
948
+
949
+    /* loop and calculate cost for all songs */
950
+    if (tcm->selected_playlist == &tcm->mytt_entry) {
951
         p = tcm->mytt_songs;
952
     } else {
953
         p = tcm->list_browsers[LB_TC_LIST_SONGS].list;
954
     }
955
-    partialQueue = jm->partial_queue;
956
-    g_print("Calculating cost for queueing a linked playlist (q:%d/size %d) ID %d\n",partialQueue,
957
-                g_list_length(p), tcm->selected_playlist->id);
958
+    
959
+    partial_queue = jm->partial_queue;
960
 
961
-    // prep parameters.
962
+    /* prep parameters */
963
     jm->priority_queue = FALSE;
964
     jm->selected_in_tunecentral = TRUE;
965
 
966
-    // Loop to evaluate entire list cost.
967
-    while(p && p->data) {
968
-         jm->selected_song = (song_entry *)p->data;
969
-         //***** Following code comes from jukefsm->enqueue_linked_song *****
970
-         // First off, figure out where the song comes from and how much it will cost.
971
-         if(jm->selected_in_tunecentral)
972
-             basecost = jm->selected_song->temp&~DOWNLOAD_BIT;
973
+    /* Loop to evaluate entire list cost */
974
+    while (p && p->data) {
975
+        ConsumeType consume_type;
976
+        WalletConsumeInfo consume_info;
977
+        guint credit_amount[WALLET_CREDIT_SOURCE_SIZE] = { 0, };
978
+        guint credit_total;
979
+
980
+        jm->selected_song = p->data;
981
+
982
+        credit_total = jukefsm_compute_wallet_transaction(credit_amount, &consume_type);
983
+
984
+        if (wallet_get_price_and_coinage(jm->wallet, consume_type, credit_total, &consume_info)) {
985
+            total_credits = total_credits + consume_info.nb_credits;
986
+            total_coinage = total_coinage + consume_info.coinage;
987
+        }
988
 
989
-         if(basecost > 1) {
990
-             consume_type = jm->priority_queue?CONSUME_TC_PLAYNOW:CONSUME_TC;
991
-         } else {
992
-             consume_type = jm->priority_queue?CONSUME_PLAYNOW:CONSUME_PLAY;
993
-         }
994
+        p = p->next;
995
 
996
-         // Ok, we have the consume type. Inquire about the price.
997
-         //price = wallet_get_price(WALLET(jm->wallet), consume_type);
998
-         if(wallet_get_price_and_coinage(WALLET(jm->wallet), consume_type, 0, &consume_info)) {
999
-             totalCredits = totalCredits + consume_info.nb_credits;
1000
-             totalCoinage = totalCoinage + consume_info.coinage;
1001
-         }
1002
-         //******************************************************************
1003
-         p=p->next;
1004
-         if(partialQueue && !--partialQueue) break; // yie-ar CodeFu
1005
+        if (partial_queue && !--partial_queue) {
1006
+            break;
1007
+        }
1008
     }
1009
 
1010
-    // Consume entire list cost in credit and money ONCE instead of consuming for each song.
1011
-    // Better doing one Connec-TT call than several and risk 'comm problems' each time...
1012
-    //***** Following code comes from jukefsm->enqueue_linked_song *****
1013
-    cc = g_new0(consume_credits_struct,1);
1014
-    cc->credits = totalCredits;
1015
-    cc->cost    = totalCoinage;
1016
-    cc->source  = 0;    // Don't care either
1017
-    cc->type    = 0;    // ...yup, you guessed right
1018
-    cc->song_id = 0;    // Ditto
1019
-    strncpy(cc->device_id,jm->client_id,63);
1020
-    
1021
-    if((subject = chick_get_subject(DATA_CONSUME_LINKED_CREDIT)))
1022
-        subject_data_set_data_size(SUBJECTDATA(subject), cc, sizeof(consume_credits_struct));
1023
-    
1024
-    g_free(cc);
1025
-    //******************************************************************
1026
+    cc.credits = total_credits;
1027
+    cc.cost    = total_coinage;
1028
+    strncpy(cc.device_id, jm->client_id, 63);
1029
+
1030
+    if ((subject = chick_get_subject(DATA_CONSUME_LINKED_CREDIT))) {
1031
+        subject_data_set_data_size(SUBJECTDATA(subject), &cc, sizeof(cc));
1032
+    }
1033
 }
1034
 
1035
 //------------------------------------------------------------------------------
1036
===== apps/jukeui/src/tcwidgets.c 1.103 vs edited =====
1037
--- 1.103/apps/jukeui/src/tcwidgets.c	2015-07-23 11:55:59 -04:00
1038
+++ edited/apps/jukeui/src/tcwidgets.c	2019-02-08 13:50:50 -05:00
1039
@@ -23,6 +23,7 @@
1040
 #include "mytouchtunes.h"
1041
 #include "featuremgr_client.h"
1042
 #include "subjectnames.h"
1043
+#include "chick.h"
1044
 #include "subject.h"
1045
 #include "subjectdata.h"
1046
 
1047
Binary files differ===== libs/wallet/pub/wallet.h 1.50 vs edited =====
1048
--- 1.50/libs/wallet/pub/wallet.h	2015-02-03 04:04:24 -05:00
1049
+++ edited/libs/wallet/pub/wallet.h	2019-02-11 16:07:19 -05:00
1050
@@ -55,6 +55,7 @@
1051
 typedef enum _ConsumeEnum   ConsumeType;
1052
 typedef enum _CreditsEnum   CreditsType;
1053
 typedef enum _WalletModeEnum WalletMode;
1054
+typedef enum _WalletCreditSource WalletCreditSource;
1055
 
1056
 /* Consume type enum */
1057
 enum _ConsumeEnum 
1058
@@ -67,8 +68,6 @@
1059
     CONSUME_LINKED_PLAYNOW,
1060
     CONSUME_SMS,
1061
     CONSUME_CUSTOM,
1062
-    CONSUME_HOMEPROMO,
1063
-    CONSUME_HOMEPROMO_PLAYNOW,
1064
     CONSUME_THIRD_PARTY,
1065
     CONSUME_SIZE,
1066
 };
1067
@@ -99,6 +98,16 @@
1068
     WALLET_MODE_NBR,
1069
 };
1070
 
1071
+enum _WalletCreditSource {
1072
+    WALLET_CREDIT_SOURCE_BASE,
1073
+    WALLET_CREDIT_SOURCE_TUNECENTRAL,
1074
+    WALLET_CREDIT_SOURCE_BANNER,
1075
+    WALLET_CREDIT_SOURCE_PLAYNOW,
1076
+    WALLET_CREDIT_SOURCE_THIRD_PARTY,
1077
+
1078
+    WALLET_CREDIT_SOURCE_SIZE,
1079
+};
1080
+
1081
 /* The structure for a credit rule. */
1082
 struct _CreditRule 
1083
 {
1084
@@ -168,19 +177,13 @@
1085
     gint        (*add_linked_credits)      (Wallet *, guint, guint,
1086
                                             guint);
1087
     void        (*add_money)               (Wallet *, guint);
1088
-    gboolean    (*consume_credits)         (Wallet *, guint, ConsumeType,
1089
-                                            WalletConsumeInfo *);
1090
-    gboolean    (*consume_n_valued_credits) (Wallet *, guint, ConsumeType,
1091
-                                            gint, gint, WalletConsumeInfo *);
1092
-    gboolean    (*consume_n_credits)       (Wallet *, guint, ConsumeType, gint,
1093
-                                            WalletConsumeInfo *);
1094
+    gboolean    (*consume_n_credits)       (Wallet *wallet, guint source, ConsumeType consume_type, const guint credit_amount[WALLET_CREDIT_SOURCE_SIZE], WalletConsumeInfo *consume_info);
1095
     void        (*transfer_credits_to_mytt_account)(Wallet *, guint, const char*);
1096
     void        (*flush_credits)           (Wallet *, WalletFlushInfo *, gboolean);
1097
     gboolean    (*is_in_session)           (Wallet *);
1098
     void        (*stop_session)            (Wallet *);
1099
-    guint       (*get_price)               (Wallet *, ConsumeType);
1100
     guint       (*get_cost)                (Wallet *);
1101
-    gboolean    (*get_price_and_coinage)   (Wallet *, ConsumeType, gint amt, WalletConsumeInfo *);
1102
+    gboolean    (*get_price_and_coinage)   (Wallet *, ConsumeType, guint, WalletConsumeInfo *);
1103
     void        (*set_cost)                (Wallet *, guint);
1104
     gboolean    (*set_money)               (Wallet *, guint);
1105
     void        (*set_mode)                (Wallet *, guint);
1106
@@ -224,29 +227,8 @@
1107
                              guint        nb_credits);
1108
 
1109
 void wallet_add_money(Wallet *wallet, guint money);
1110
-/*
1111
- * This public method is used to consume credits from the wallet.
1112
- * @ wallet      : Instance of the wallet object
1113
- * @ source      : Not defined yet. This is for log purpose 
1114
- * @ consume_type: Type of consume you want to use. See the Consume type
1115
- *                 enum to know which one to use
1116
- * @ return      : return TRUE is successful, FALSE otherwise       
1117
- */
1118
-//FIXME: 
1119
-gboolean wallet_consume_credits(Wallet *wallet, guint source, 
1120
-                                ConsumeType consume_type, 
1121
-                                WalletConsumeInfo *consume_info);
1122
-
1123
-// Consume the credits, but force a value. This is for ConnecTT.
1124
-gboolean wallet_consume_n_valued_credits(Wallet *wallet, guint source, 
1125
-                                ConsumeType consume_type, gint price, gint value, 
1126
-                                WalletConsumeInfo *consume_info);
1127
 
1128
-// alternate version for comsuming generic credits (i.e. SMS)
1129
-// variable consume types (SMS/custom) only
1130
-gboolean wallet_consume_n_credits(Wallet *wallet, guint source,
1131
-                                ConsumeType consume_type, int amount,
1132
-                                WalletConsumeInfo *consume_info);
1133
+gboolean wallet_consume_n_credits(Wallet *wallet, guint source, ConsumeType consume_type, const guint credit_amount[WALLET_CREDIT_SOURCE_SIZE], WalletConsumeInfo *consume_info);
1134
 
1135
 /*
1136
  * This public method is used to flush credits from the wallet.
1137
@@ -284,24 +266,14 @@
1138
 gboolean wallet_force_linked_credit_rules(Wallet *wallet, gint cost, gint credits_value);
1139
 gboolean wallet_force_linked_credit_rules_string(Wallet *wallet, gchar *rule_string);
1140
 
1141
-/* 
1142
- * This functions is used to get the price for a type of consume
1143
- * @ wallet:        Instance of the wallet
1144
- * @ consume_type:  Type of consume 
1145
- * @ return:        Number of credits (price)
1146
- * Note: I moved that in the public domain so we can query how 
1147
- * much a consume type costs. This is required for ConnecTT.
1148
- *                                          -- Burdo
1149
- */
1150
-guint wallet_get_price(Wallet *, ConsumeType);
1151
-
1152
 /* used to set the cost of the wallet */
1153
 void  wallet_set_cost(Wallet *, guint);
1154
 
1155
 guint  wallet_get_cost(Wallet *);
1156
 gboolean wallet_set_money(Wallet *, guint money);
1157
-gboolean wallet_get_price_and_coinage(Wallet *, ConsumeType, gint amt, WalletConsumeInfo *consume_info);
1158
 
1159
+gboolean wallet_get_price_and_coinage(Wallet *wallet, ConsumeType consume_type, guint credit_amount, WalletConsumeInfo *consume_info);
1160
+
1161
 void wallet_set_mode(Wallet *, guint mode);
1162
 void wallet_set_third_party_id(Wallet *, guint id);
1163
 void wallet_set_mytt_user_rank(Wallet *, guint rank);
1164
===== libs/wallet/src/wallet.c 1.152 vs edited =====
1165
--- 1.152/libs/wallet/src/wallet.c	2017-02-23 17:42:10 -05:00
1166
+++ edited/libs/wallet/src/wallet.c	2019-02-12 10:51:39 -05:00
1167
@@ -26,6 +26,8 @@
1168
 #include "hash.h"
1169
 #endif
1170
 
1171
+/* #define DEBUG */
1172
+
1173
 #define WALLET_PERSIST_VALUES   "wallet_persistence_values"
1174
 #define WALLET_PERSIST_THIRD_PARTY_VALUES   "wallet_persistence_third_party_values"
1175
 #define WALLET_PERSIST_CREDITS  "wallet_persistence_credits"
1176
@@ -70,7 +72,6 @@
1177
 static void     wallet_use_credits                  (Wallet *, guint, 
1178
                                                      WalletConsumeInfo *, gboolean);
1179
 static GList *  wallet_dup_credit_rules             (Wallet *, GList *);
1180
-static void     wallet_setup_consume_prices         (Wallet *);
1181
 #ifndef STANDALONE
1182
 static guint    wallet_compute_promo_credits        (Wallet *, guint);
1183
 static void     wallet_serializable_save_thyself    (Wallet *);
1184
@@ -96,12 +97,6 @@
1185
                                               gpointer data,
1186
                                               gpointer user_data);
1187
 
1188
-static void     wallet_surcharge_playnow_callback   (Subject *subject,
1189
-                                                     gpointer data,
1190
-                                                     gpointer user_data);
1191
-static void     wallet_surcharge_tc_callback        (Subject *subject,
1192
-                                                     gpointer data,
1193
-                                                     gpointer user_data);
1194
 static void     wallet_flush_credits_callback       (Subject *subject,
1195
                                                      gpointer data,
1196
                                                      gpointer user_data);
1197
@@ -116,10 +111,8 @@
1198
                                                      gpointer user_data);
1199
                                                      
1200
 static void wallet_save_flushed_credits( guint nb_credits, gfloat coinage);
1201
-static void wallet_save_billing_split( BillingSplitType type,
1202
-                                       gfloat           value);
1203
-static void wallet_save_credits_used( CreditsUsedType type,
1204
-                                      guint           value);
1205
+static void wallet_save_billing_split(BillingSplitType type, gfloat value);
1206
+static void wallet_save_credits_used(CreditsUsedType type, guint value);
1207
 static void wallet_save_credits( CreditsType type,
1208
                                  guint       value);
1209
 static void wallet_save_coinage( CoinageType type, 
1210
@@ -142,9 +135,6 @@
1211
 
1212
 //static void wallet_print_current_credit_rules(Wallet *wallet);
1213
 
1214
-//static void     wallet_surcharge_linked_callback    (Subject *subject,
1215
-//                                                     gpointer data,
1216
-//                                                     gpointer user_data);
1217
 #endif
1218
 
1219
 /* Private members */
1220
@@ -194,12 +184,6 @@
1221
     
1222
     gboolean session_credit_rules;         // Are we in a credit rules session? 
1223
 
1224
-
1225
-    guint price_play;                      // Fixed price for a play 
1226
-    guint surcharge_playnow;               // Surcharge (credits) for a play now
1227
-    guint surcharge_tc;                    // Surcharge (credits) for a tc play
1228
-    guint surcharge_linked;                // Surcharge (credits) for a linked play (ie:merit)
1229
-
1230
     guint cost;                            // Use for counter top machines for the cost
1231
 
1232
     gboolean persistence_enabled;          // If persistence is required for this wallet.
1233
@@ -312,61 +296,18 @@
1234
 }
1235
 
1236
 gboolean
1237
-wallet_consume_credits(Wallet       *wallet, 
1238
-                       guint        source, 
1239
-                       ConsumeType  consume_type,
1240
-                       WalletConsumeInfo *consume_info)
1241
+wallet_consume_n_credits(Wallet *wallet, guint source, ConsumeType consume_type, const guint credit_amount[WALLET_CREDIT_SOURCE_SIZE], WalletConsumeInfo *consume_info)
1242
 {
1243
     g_return_val_if_fail(IS_WALLET(wallet), FALSE);
1244
+    g_return_val_if_fail(credit_amount, FALSE);
1245
     g_return_val_if_fail((consume_type < CONSUME_SIZE), FALSE);
1246
 
1247
-    if (wallet->priv->dispose_has_run)
1248
-        return FALSE;
1249
-
1250
-    return WALLET_GET_CLASS(wallet)->consume_credits(wallet, 
1251
-                                                     source,
1252
-                                                     consume_type,
1253
-                                                     consume_info);
1254
-}
1255
-
1256
-gboolean
1257
-wallet_consume_n_valued_credits(Wallet        *wallet, 
1258
-                              guint         source, 
1259
-                              ConsumeType   consume_type,
1260
-                              gint         price,
1261
-                              gint         value,
1262
-                              WalletConsumeInfo *consume_info)
1263
-{
1264
-    g_return_val_if_fail(IS_WALLET(wallet), FALSE);
1265
-    g_return_val_if_fail((consume_type < CONSUME_SIZE), FALSE);
1266
-
1267
-    if (wallet->priv->dispose_has_run)
1268
+    /* XXX: Why? */
1269
+    if (wallet->priv->dispose_has_run) {
1270
         return FALSE;
1271
+    }
1272
 
1273
-    return WALLET_GET_CLASS(wallet)->consume_n_valued_credits(wallet, 
1274
-                                                            source,
1275
-                                                            consume_type,
1276
-                                                            price,
1277
-                                                            value,
1278
-                                                            consume_info);
1279
-}
1280
-
1281
-gboolean
1282
-wallet_consume_n_credits(Wallet       *wallet, 
1283
-                       guint        source, 
1284
-                       ConsumeType  consume_type, gint amt,
1285
-                       WalletConsumeInfo *consume_info)
1286
-{
1287
-    g_return_val_if_fail(IS_WALLET(wallet), FALSE);
1288
-    g_return_val_if_fail((consume_type < CONSUME_SIZE), FALSE);
1289
-
1290
-    if (wallet->priv->dispose_has_run)
1291
-        return FALSE;
1292
-
1293
-    return WALLET_GET_CLASS(wallet)->consume_n_credits(wallet, 
1294
-                                                     source,
1295
-                                                     consume_type, amt,
1296
-                                                     consume_info);
1297
+    return WALLET_GET_CLASS(wallet)->consume_n_credits(wallet, source, consume_type, credit_amount, consume_info);
1298
 }
1299
 
1300
 void
1301
@@ -414,28 +355,19 @@
1302
     WALLET_GET_CLASS(wallet)->stop_session(wallet);
1303
 }
1304
 
1305
-guint
1306
-wallet_get_price(Wallet *wallet, ConsumeType consume_type)
1307
-{
1308
-    g_return_val_if_fail(IS_WALLET(wallet), -1);
1309
-    g_return_val_if_fail((consume_type < CONSUME_SIZE), -1);
1310
-
1311
-    if (wallet->priv->dispose_has_run)
1312
-        return -1;
1313
-
1314
-    return WALLET_GET_CLASS(wallet)->get_price(wallet, consume_type);
1315
-}
1316
-
1317
 gboolean
1318
-wallet_get_price_and_coinage(Wallet *wallet, ConsumeType consume_type, gint amt, WalletConsumeInfo *consume_info)
1319
+wallet_get_price_and_coinage(Wallet *wallet, ConsumeType consume_type, guint credit_amount, WalletConsumeInfo *consume_info)
1320
 {
1321
-    g_return_val_if_fail(IS_WALLET(wallet), -1);
1322
-    g_return_val_if_fail((consume_type < CONSUME_SIZE), -1);
1323
+    g_return_val_if_fail(IS_WALLET(wallet), FALSE);
1324
+    g_return_val_if_fail((consume_type < CONSUME_SIZE), FALSE);
1325
+    g_return_val_if_fail(credit_amount, FALSE);
1326
 
1327
-    if (wallet->priv->dispose_has_run)
1328
-        return -1;
1329
+    /* XXX: Why? */
1330
+    if (wallet->priv->dispose_has_run) {
1331
+        return FALSE;
1332
+    }
1333
 
1334
-    return WALLET_GET_CLASS(wallet)->get_price_and_coinage(wallet, consume_type, amt, consume_info);
1335
+    return WALLET_GET_CLASS(wallet)->get_price_and_coinage(wallet, consume_type, credit_amount, consume_info);
1336
 }
1337
 
1338
 void
1339
@@ -516,18 +448,6 @@
1340
                                             wallet))
1341
             ret = FALSE;
1342
 
1343
-        if(!chick_create_listen_subject_xml(xml, XML_PLAYNOW_SURCHARGE,
1344
-                                            wallet_surcharge_playnow_callback,
1345
-                                            FALSE,
1346
-                                            wallet))
1347
-            ret = FALSE;
1348
-
1349
-        if(!chick_create_listen_subject_xml(xml, XML_TC_SURCHARGE,
1350
-                                            wallet_surcharge_tc_callback,
1351
-                                            FALSE,
1352
-                                            wallet))
1353
-            ret = FALSE;
1354
-
1355
         if(!chick_create_subject_xml(xml, XML_SERVICE_CREDITS_POOL))
1356
             ret = FALSE;
1357
         if(!chick_create_subject_xml(xml, XML_PROMO_CREDITS_POOL))
1358
@@ -930,280 +850,101 @@
1359
     wallet_evaluate_money(wallet, money); 
1360
 }
1361
 
1362
-static gboolean
1363
-wallet_consume_n_valued_credits_impl(Wallet       *wallet, 
1364
-                                   guint        source, 
1365
-                                   ConsumeType  consume_type,
1366
-                                   gint         price,
1367
-                                   gint         value,
1368
-                                   WalletConsumeInfo *consume_info)
1369
+static guint
1370
+wallet_sum_array(const guint *array, gsize n)
1371
 {
1372
-    guint credits_available = 0;
1373
-    WalletConsumeInfo wallet_consume_info;
1374
-
1375
-    tracep("Called");
1376
+    guint sum = 0;
1377
+    gsize i;
1378
 
1379
-    /* Tell me the truth, are we rich? */
1380
-    credits_available = wallet_get_total_credits(wallet);   // Optimize this!
1381
-    
1382
-    /* if price is not specified by caller, ask the wallet how much this consume should costs */
1383
-    if(price < 0) {
1384
-        price = wallet_get_price(wallet, consume_type);
1385
+    for (i = 0; i < n; i++) {
1386
+        /* XXX: Check overflow... */
1387
+        sum += array[i];
1388
     }
1389
-    
1390
-    /* Check if the wallet has enough credits to consume and if pricing is correct */
1391
-    if(price <= 0 || credits_available < price) {
1392
-        warnp("Can't consume %d credits. Wallet has only %d credits!", price,
1393
-              credits_available);
1394
-        return FALSE;
1395
-    }
1396
-
1397
-    /* Initialize the consume information */
1398
-    memset(&wallet_consume_info, 0, sizeof(wallet_consume_info));
1399
-
1400
-    /* Check if the wallet has enough credit to consume */
1401
-    wallet_use_credits(wallet, price, &wallet_consume_info, TRUE); 
1402
-    
1403
-    /* If a credit value was passed, force it as coinage */
1404
-    if(value >= 0)
1405
-        wallet_consume_info.coinage = value*price;
1406
-    
1407
-    /* Save the number of credits */
1408
-    wallet_consume_info.nb_credits = price;
1409
-
1410
-#ifndef STANDALONE
1411
-    switch(consume_type) {
1412
-    case CONSUME_PLAY:
1413
-        /* If paid credits are use for the consume, save the coinage value 
1414
-         * for the billing split
1415
-         */
1416
-
1417
-        if(wallet_consume_info.coinage > 0)
1418
-            wallet_save_billing_split(BS_JUKEBOX,
1419
-                                      wallet_consume_info.coinage); 
1420
 
1421
-        /* Bookkeep the credits used */
1422
-        wallet_save_credits_used(CREDITS_USED_PLAY, 
1423
-                                 price); 
1424
-        break;
1425
-
1426
-    case CONSUME_PLAYNOW:
1427
-        
1428
-        if(wallet_consume_info.coinage > 0)
1429
-            wallet_save_billing_split(BS_JUKEBOX, 
1430
-                                      wallet_consume_info.coinage); 
1431
-
1432
-        /* Here we must bookkeep credits separately because a playnow is
1433
-         * 1 normal play + a surcharge for the playnow, so 1 credit used
1434
-         * for a play, and 2 credits for a playnow. Hmm?
1435
-         */
1436
-        wallet_save_credits_used(CREDITS_USED_PLAY, 
1437
-                                 wallet->priv->price_play);
1438
-        wallet_save_credits_used(CREDITS_USED_PLAYNOW, 
1439
-                                 wallet->priv->surcharge_playnow);
1440
-        break;
1441
-
1442
-    case CONSUME_TC:
1443
-        if(wallet_consume_info.coinage > 0)
1444
-            wallet_save_billing_split( BS_TC,
1445
-                                       wallet_consume_info.coinage); 
1446
-
1447
-        wallet_save_credits_used(CREDITS_USED_TC, 
1448
-                                 price);
1449
-        break;
1450
-
1451
-    case CONSUME_TC_PLAYNOW:
1452
-        if(wallet_consume_info.coinage > 0)
1453
-            wallet_save_billing_split(BS_TC,
1454
-                                      wallet_consume_info.coinage); 
1455
-
1456
-        wallet_save_credits_used(CREDITS_USED_TC, 
1457
-                                 wallet->priv->price_play +
1458
-                                 wallet->priv->surcharge_tc);
1459
-        wallet_save_credits_used(CREDITS_USED_PLAYNOW, 
1460
-                                 wallet->priv->surcharge_playnow);
1461
-
1462
-        break;
1463
-    case CONSUME_LINKED_PLAY:
1464
-        // gamelink implementation is wack. It's consuming a credit before it's insertion.
1465
-        // What do I do?
1466
-        break;
1467
-    case CONSUME_LINKED_PLAYNOW:
1468
-        break;
1469
-    case CONSUME_SMS:
1470
-    case CONSUME_CUSTOM:
1471
-        break;
1472
-    case CONSUME_HOMEPROMO:
1473
-        wallet_save_credits_used(CREDITS_USED_HOMEPROMO, price);
1474
-        break;
1475
-    case CONSUME_HOMEPROMO_PLAYNOW:
1476
-        wallet_save_credits_used(CREDITS_USED_HOMEPROMO, price - wallet->priv->surcharge_playnow);
1477
-        wallet_save_credits_used(CREDITS_USED_PLAYNOW, wallet->priv->surcharge_playnow);
1478
-        break;
1479
-
1480
-    default:
1481
-        // Something wrong is going on here. Bail out.
1482
-        return FALSE;
1483
-        break;
1484
-    }
1485
-#endif
1486
-
1487
-    /* Stop the current credit rule session and put the remaining money
1488
-     * in the session money.
1489
-     */
1490
-    wallet->priv->session_credit_rules = FALSE;
1491
-    wallet->priv->session_money = wallet->priv->remaining_money;
1492
-
1493
-    // if a new credit rules was set during a session, it's time to use it 
1494
-    if(wallet->priv->new_credit_rules != NULL) {
1495
-        debugp("Changing the current credit rules for the new one");
1496
-        g_object_set(G_OBJECT(wallet), 
1497
-                     "credit-rules", 
1498
-                     wallet->priv->new_credit_rules, 
1499
-                     NULL);
1500
-        wallet_delete_credit_rules(wallet->priv->new_credit_rules);
1501
-        wallet->priv->new_credit_rules = NULL;
1502
-    }
1503
-        
1504
-    /* Persistence */
1505
-#ifndef STANDALONE
1506
-    wallet_serializable_save_thyself(wallet);
1507
-#endif
1508
-
1509
-    g_signal_emit(wallet,
1510
-                  WALLET_GET_CLASS(wallet)->signal_id[CREDITS_CONSUMED_SIGNAL],
1511
-                  0,
1512
-                  NULL);
1513
-    
1514
-    if(consume_info)
1515
-        memcpy(consume_info, &wallet_consume_info, sizeof(wallet_consume_info));
1516
-
1517
-    return TRUE; 
1518
+    return sum;
1519
 }
1520
 
1521
-
1522
 static gboolean
1523
-wallet_consume_credits_impl(Wallet      *wallet, 
1524
-                            guint       source, 
1525
-                            ConsumeType consume_type,
1526
-                            WalletConsumeInfo *consume_info)
1527
-{
1528
-    /* Hack of the year! */
1529
-    return wallet_consume_n_valued_credits_impl(wallet, source, consume_type, -1, -1, consume_info);
1530
-}
1531
-
1532
-
1533
-static gboolean
1534
-wallet_consume_n_credits_impl(Wallet       *wallet, 
1535
-                            guint        source, 
1536
-                            ConsumeType  consume_type, gint price,
1537
-                            WalletConsumeInfo *consume_info)
1538
+wallet_consume_n_credits_impl(Wallet *wallet, guint source, ConsumeType consume_type, const guint credit_amount[WALLET_CREDIT_SOURCE_SIZE], WalletConsumeInfo *consume_info)
1539
 {
1540
+    guint credit_total = wallet_sum_array(credit_amount, WALLET_CREDIT_SOURCE_SIZE);
1541
     guint credits_available = 0;
1542
-    WalletConsumeInfo wallet_consume_info;
1543
+    WalletConsumeInfo wallet_consume_info = { 0, };
1544
+    enum _BillingSplitEnum bs = BS_SIZE;  /* BS_SIZE == not used */
1545
+    gboolean do_save = FALSE;
1546
 
1547
-    tracep("Called");
1548
+    g_return_val_if_fail(credit_total, FALSE);
1549
 
1550
     /* Tell me the truth, are we rich? */
1551
-    credits_available = wallet_get_total_credits(wallet);   // Optimize this!
1552
+    credits_available = wallet_get_total_credits(wallet);
1553
 
1554
     /* Check if the wallet has enough credits to consume */
1555
-    if(price < 0 || credits_available < price) {
1556
-        warnp("Can't consume %d credits. Wallet has only %d credits!", price,
1557
-              credits_available);
1558
+    if (credits_available < credit_total) {
1559
+        g_warning(G_STRLOC ": Can't consume %u credits. Wallet has only %u credits!", credit_total, credits_available);
1560
         return FALSE;
1561
     }
1562
 
1563
-    /* Initialize the consume information */
1564
-    memset(&wallet_consume_info, 0, sizeof(wallet_consume_info));
1565
-
1566
 #ifndef STANDALONE
1567
-    switch(consume_type) {
1568
-    case CONSUME_PLAY:
1569
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1570
-        if(wallet_consume_info.coinage > 0)
1571
-            wallet_save_billing_split(BS_JUKEBOX,
1572
-                                      wallet_consume_info.coinage); 
1573
+    switch (consume_type) {
1574
+        case CONSUME_PLAY:
1575
+            bs = BS_JUKEBOX;
1576
+            do_save = TRUE;
1577
+            break;
1578
 
1579
-        wallet_save_credits_used(CREDITS_USED_PLAY, 
1580
-                                 price);
1581
-        break;
1582
+        case CONSUME_PLAYNOW:
1583
+            bs = BS_JUKEBOX;
1584
+            do_save = TRUE;
1585
+            break;
1586
 
1587
-    case CONSUME_PLAYNOW:
1588
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1589
-        if(wallet_consume_info.coinage > 0)
1590
-            wallet_save_billing_split(BS_JUKEBOX, 
1591
-                                      wallet_consume_info.coinage);
1592
+        case CONSUME_TC:
1593
+            bs = BS_TC;
1594
+            do_save = TRUE;
1595
+            break;
1596
 
1597
-        wallet_save_credits_used(CREDITS_USED_PLAY, 
1598
-                                 price - wallet->priv->surcharge_playnow);
1599
-        wallet_save_credits_used(CREDITS_USED_PLAYNOW, 
1600
-                                 wallet->priv->surcharge_playnow);
1601
-        break;
1602
+        case CONSUME_TC_PLAYNOW:
1603
+            bs = BS_TC;
1604
+            do_save = TRUE;
1605
+            break;
1606
 
1607
-    case CONSUME_TC:
1608
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1609
-        if(wallet_consume_info.coinage > 0)
1610
-            wallet_save_billing_split( BS_TC,
1611
-                                       wallet_consume_info.coinage); 
1612
+        default:
1613
+            break;
1614
+    }
1615
+#endif /* !STANDALONE */
1616
 
1617
-        wallet_save_credits_used(CREDITS_USED_TC, 
1618
-                                 price);
1619
-        break;
1620
+    wallet_use_credits(wallet, credit_total, &wallet_consume_info, TRUE);
1621
 
1622
-    case CONSUME_TC_PLAYNOW:
1623
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1624
-        if(wallet_consume_info.coinage > 0)
1625
-            wallet_save_billing_split(BS_TC,
1626
-                                      wallet_consume_info.coinage); 
1627
+    if (bs != BS_SIZE && wallet_consume_info.coinage > 0) {
1628
+        wallet_save_billing_split(bs, wallet_consume_info.coinage); 
1629
+    }
1630
 
1631
-        wallet_save_credits_used(CREDITS_USED_TC, 
1632
-                                 price - wallet->priv->surcharge_playnow);
1633
-        wallet_save_credits_used(CREDITS_USED_PLAYNOW, 
1634
-                                 wallet->priv->surcharge_playnow);
1635
+    if (do_save) {
1636
+        guint base_total = credit_amount[WALLET_CREDIT_SOURCE_BASE] +
1637
+                           credit_amount[WALLET_CREDIT_SOURCE_TUNECENTRAL] +
1638
+                           credit_amount[WALLET_CREDIT_SOURCE_BANNER];
1639
 
1640
-        break;
1641
-    case CONSUME_SMS:
1642
-    case CONSUME_CUSTOM:
1643
-        /* Check if the wallet has enough credit to consume */
1644
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1645
-        // ponder the bookkeeping aspect of this
1646
-        break;
1647
-    case CONSUME_HOMEPROMO:
1648
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1649
+        if (base_total) {
1650
+            CreditsUsedType used = CREDITS_USED_PLAY;
1651
 
1652
-        wallet_save_credits_used(CREDITS_USED_HOMEPROMO, price);
1653
-        break;
1654
-    case CONSUME_HOMEPROMO_PLAYNOW:
1655
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1656
+            /*
1657
+             * In an ideal world, we should be able to deduce that we had a TC play simply by looking
1658
+             * if we have credits in WALLET_CREDIT_SOURCE_TUNECENTRAL. In reality, when we play from
1659
+             * recom for example, we have a "consume_type" of TC and 2 WALLET_CREDIT_SOURCE_BASE. As
1660
+             * a result, we also check the "consume_type" here.
1661
+             */
1662
+            if (credit_amount[WALLET_CREDIT_SOURCE_TUNECENTRAL] || consume_type == CONSUME_TC || consume_type == CONSUME_TC_PLAYNOW) {
1663
+                used = CREDITS_USED_TC;
1664
+            }
1665
 
1666
-        wallet_save_credits_used(CREDITS_USED_HOMEPROMO, 
1667
-                                 price - wallet->priv->surcharge_playnow);
1668
-        wallet_save_credits_used(CREDITS_USED_PLAYNOW, 
1669
-                                 wallet->priv->surcharge_playnow);
1670
-        break;
1671
-    case CONSUME_THIRD_PARTY:
1672
-        wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1673
-        if(wallet_consume_info.coinage > 0) {
1674
-            // Do the split and bookkeeping here.
1675
-            // Do we need a negative entry?
1676
-            //wallet_save_billing_split(BS_JUKEBOX, wallet_consume_info.coinage); 
1677
-            
1678
+            wallet_save_credits_used(used, base_total);
1679
+        }
1680
+
1681
+        if (credit_amount[WALLET_CREDIT_SOURCE_PLAYNOW]) {
1682
+            wallet_save_credits_used(CREDITS_USED_PLAYNOW, credit_amount[WALLET_CREDIT_SOURCE_PLAYNOW]);
1683
         }
1684
-        // More bookkeeping stuff ???
1685
-        //wallet_save_credits_used(CREDITS_USED_PLAY, price);
1686
-        break;
1687
-    default:
1688
-        warnp("Can't consume %d credits of non-custom type!", price);
1689
-        return FALSE;
1690
-        break;
1691
     }
1692
-#else
1693
-    wallet_use_credits(wallet, price, &wallet_consume_info, TRUE);
1694
-#endif
1695
 
1696
     /* Save the number of credits */
1697
-    wallet_consume_info.nb_credits = price;
1698
+    wallet_consume_info.nb_credits = credit_total;
1699
 
1700
     /* Stop the current credit rule session and put the remaining money
1701
      * in the session money.
1702
@@ -1238,7 +979,6 @@
1703
     return TRUE; 
1704
 }
1705
 
1706
-
1707
 static void
1708
 wallet_flush_credits_impl(Wallet *wallet, WalletFlushInfo *flush_info, gboolean bookkeep)
1709
 {
1710
@@ -1423,80 +1163,33 @@
1711
     wallet_serializable_save_thyself(wallet);
1712
 }
1713
 
1714
-/* 
1715
- * This functions is used to get the price for a type of consume
1716
- * @ wallet:        Instance of the wallet
1717
- * @ consume_type:  Type of consume 
1718
- * @ return:        Number of credits (price) 
1719
- */
1720
-static guint
1721
-wallet_get_price_impl(Wallet *wallet, ConsumeType consume_type)
1722
-{
1723
-    guint price = -1;
1724
-
1725
-    switch(consume_type) {
1726
-        case CONSUME_PLAY:
1727
-            price = wallet->priv->price_play;
1728
-            break;
1729
-        case CONSUME_PLAYNOW:
1730
-            price = wallet->priv->price_play + wallet->priv->surcharge_playnow;
1731
-            break;
1732
-        case CONSUME_TC:
1733
-            price = wallet->priv->price_play + wallet->priv->surcharge_tc;
1734
-            break;
1735
-        case CONSUME_TC_PLAYNOW:
1736
-            price = wallet->priv->price_play + wallet->priv->surcharge_tc +
1737
-                    wallet->priv->surcharge_playnow;
1738
-            break;
1739
-        case CONSUME_LINKED_PLAY:
1740
-        case CONSUME_LINKED_PLAYNOW:
1741
-            break;
1742
-        default:
1743
-            break; 
1744
-    }
1745
-
1746
-    return price;
1747
-}
1748
-
1749
 static gboolean
1750
-wallet_get_price_and_coinage_impl(Wallet *wallet, ConsumeType consume_type, gint amt, WalletConsumeInfo *consume_info)
1751
+wallet_get_price_and_coinage_impl(Wallet *wallet, ConsumeType consume_type, guint credit_amount, WalletConsumeInfo *consume_info)
1752
 {
1753
     guint credits_available = 0;
1754
     guint credits_price = 0;
1755
     WalletConsumeInfo wallet_consume_info;
1756
-    
1757
+
1758
     credits_available = wallet_get_total_credits(wallet);
1759
-    
1760
-    /* Ask the wallet how this consume costs */
1761
-    if(amt>0)
1762
-        credits_price = amt;
1763
-    else
1764
-        credits_price = wallet_get_price(wallet, consume_type);
1765
-    
1766
-    /* If something went wrong, report the error */
1767
-    if(credits_price < 0) {
1768
-        warnp("Can't get pricing for this consume type!");
1769
-        return FALSE;
1770
-    }
1771
-    
1772
+
1773
     /* Check if the wallet has enough credits to consume */
1774
-    if(credits_available < credits_price) {
1775
-        warnp("Can't consumed %d credits. Wallet has only %d credits!", credits_price,
1776
-              credits_available);
1777
+    if (credits_available < credit_amount) {
1778
+        g_warning(G_STRLOC ": Can't consumed %u credits. Wallet has only %u credits!", credit_amount, credits_available);
1779
         return FALSE;
1780
     }
1781
-    
1782
+
1783
     /* Initialize the consume information */
1784
     memset(&wallet_consume_info, 0, sizeof(wallet_consume_info));
1785
-    
1786
+
1787
     /* Check if the wallet has enough credit to consume */
1788
-    wallet_use_credits(wallet, credits_price, &wallet_consume_info, FALSE);
1789
-    
1790
+    wallet_use_credits(wallet, credit_amount, &wallet_consume_info, FALSE);
1791
+
1792
     /* Save the number of credits */
1793
     wallet_consume_info.nb_credits = credits_price;
1794
-    
1795
-    if(consume_info)
1796
+
1797
+    if (consume_info) {
1798
         memcpy(consume_info, &wallet_consume_info, sizeof(wallet_consume_info));
1799
+    }
1800
 
1801
     return TRUE;
1802
 }
1803
@@ -3170,40 +2863,6 @@
1804
 }
1805
 #endif
1806
 
1807
-/* 
1808
- * Function used to get surcharge prices
1809
- * @ wallet: Instance of the wallet
1810
- */
1811
-static void
1812
-wallet_setup_consume_prices(Wallet *wallet)
1813
-{
1814
-    wallet->priv->price_play = 1; // Price for one play
1815
-#ifndef STANDALONE
1816
-    Subject *subject = NULL;
1817
-
1818
-    if((subject = chick_get_subject(XML_PLAYNOW_SURCHARGE))) {
1819
-        wallet->priv->surcharge_playnow = *(gint *)subject_data_get_data(SUBJECTDATA(subject));
1820
-    }
1821
-    else {
1822
-        warnp("The subject surcharge_playnow is not created or its value is"
1823
-              "NULL");
1824
-        wallet->priv->surcharge_playnow = 1;   // Default value
1825
-    }
1826
-
1827
-    if((subject = chick_get_subject(XML_TC_SURCHARGE))) {
1828
-        wallet->priv->surcharge_tc = *(gint *)subject_data_get_data(SUBJECTDATA(subject));
1829
-    }
1830
-    else {
1831
-        warnp("The subject surcharge_tc is not created or its value is"
1832
-              "NULL");
1833
-        wallet->priv->surcharge_tc = 1; // Default value
1834
-    }
1835
-#else
1836
-        wallet->priv->surcharge_playnow = 1;   // Default value
1837
-        wallet->priv->surcharge_tc = 1; // Default value
1838
-#endif
1839
-}
1840
-
1841
 static GList * 
1842
 wallet_dup_credit_rules(Wallet *wallet, GList *src)
1843
 {
1844
@@ -3383,36 +3042,6 @@
1845
     wallet_save_moneylog(wallet->priv->moneylog);
1846
 }
1847
 
1848
-static void
1849
-wallet_surcharge_playnow_callback(Subject *subject,
1850
-                                  gpointer data,
1851
-                                  gpointer user_data)
1852
-{
1853
-    Wallet *wallet = WALLET(user_data);
1854
-    
1855
-    tracep("Called");
1856
-    
1857
-    g_return_if_fail(IS_WALLET(wallet));
1858
-    g_return_if_fail(data != NULL);
1859
-    
1860
-    wallet->priv->surcharge_playnow = *(guint *)data;
1861
-}
1862
-
1863
-static void
1864
-wallet_surcharge_tc_callback(Subject *subject,
1865
-                             gpointer data,
1866
-                             gpointer user_data)
1867
-{
1868
-    Wallet *wallet = WALLET(user_data);
1869
-    
1870
-    tracep("Called");
1871
-    
1872
-    g_return_if_fail(IS_WALLET(wallet));
1873
-    g_return_if_fail(data != NULL);
1874
-    
1875
-    wallet->priv->surcharge_tc = *(guint *)data;
1876
-}
1877
-
1878
 /* Chick callback */
1879
 static void
1880
 wallet_flush_credits_callback(Subject *subject, gpointer data, 
1881
@@ -3510,32 +3139,33 @@
1882
 static void
1883
 wallet_consume_third_party_credits(Subject *subject, gpointer data, gpointer user_data)
1884
 {
1885
-    Wallet *wallet = WALLET(user_data);
1886
-    LoggerThirdPartyLog log;
1887
-    Subject *log_subject = NULL;
1888
-    guint credits = data?*(guint *)data:0;
1889
+    Wallet *wallet = user_data;
1890
+    LoggerThirdPartyLog log = { 0, };
1891
+    Subject *log_subject;
1892
     WalletConsumeInfo consume_info;
1893
-    
1894
-    g_return_if_fail(wallet);
1895
-    
1896
-    // source is unused...funny!
1897
-    if(wallet_consume_n_credits(wallet, 0, CONSUME_THIRD_PARTY, credits, &consume_info)) {
1898
-        // Log the resource order
1899
-        log.origin = ORIGIN_THIRD_PARTY;
1900
-        log.third_party_id = wallet->priv->third_party_id;
1901
-        log.credits = credits;
1902
-        log.money = consume_info.coinage;
1903
-        log.credit_card_money = 0;
1904
-        log.event = THIRD_PARTY_CREDITS_CONSUMED;
1905
-        log.money_type = -1; //i.e., not applicable
1906
-        log_subject = chick_get_subject(DATA_LOGGING_SAVE_THIRDPARTYLOG);
1907
-        
1908
-        if (log_subject) {
1909
-            subject_data_set_data_size(SUBJECTDATA(log_subject), &log, sizeof(log));
1910
-        }
1911
-        
1912
-        // Bookkeep money consumption
1913
-        //wallet_save_billing_split(BS_PLUGINS, consumed_money);
1914
+    guint credit_amount[WALLET_CREDIT_SOURCE_SIZE] = { 0, };
1915
+
1916
+    credit_amount[WALLET_CREDIT_SOURCE_THIRD_PARTY] = data ? *(guint *)data : 0;
1917
+
1918
+    if (!wallet_consume_n_credits(wallet, 0, CONSUME_THIRD_PARTY, credit_amount, &consume_info)) {
1919
+        g_warning(G_STRLOC ": wallet_consume_n_credits failed");
1920
+        return;
1921
+    }
1922
+
1923
+    log.origin = ORIGIN_THIRD_PARTY;
1924
+    log.third_party_id = wallet->priv->third_party_id;
1925
+    log.credits = credit_amount[WALLET_CREDIT_SOURCE_THIRD_PARTY];
1926
+    log.money = consume_info.coinage;
1927
+    log.credit_card_money = 0;
1928
+    log.event = THIRD_PARTY_CREDITS_CONSUMED;
1929
+    log.money_type = -1; /* i.e., not applicable */
1930
+
1931
+    log_subject = chick_get_subject(DATA_LOGGING_SAVE_THIRDPARTYLOG);
1932
+
1933
+    if (log_subject) {
1934
+        subject_data_set_data_size(SUBJECTDATA(log_subject), &log, sizeof(log));
1935
+    } else {
1936
+        g_warning(G_STRLOC ": Failed to get subject '" DATA_LOGGING_SAVE_THIRDPARTYLOG "'");
1937
     }
1938
 }
1939
 
1940
@@ -3552,21 +3182,6 @@
1941
     }
1942
 }
1943
 
1944
-//static void
1945
-//wallet_surcharge_linked_callback(Subject *subject,
1946
-//                                 gpointer data,
1947
-//                                 gpointer user_data)
1948
-//{
1949
-//    Wallet *wallet = WALLET(user_data);
1950
-//    
1951
-//    tracep("Called");
1952
-//    
1953
-//    g_return_if_fail(IS_WALLET(wallet));
1954
-//    g_return_if_fail(data != NULL);
1955
-//    
1956
-//    wallet->priv->surcharge_linked = *(guint *)data;
1957
-//}
1958
-
1959
 static GList *
1960
 wallet_credit_rules_to_glist(CreditRule *rules, size_t size, CreditRule *extra)
1961
 {
1962
@@ -3645,7 +3260,6 @@
1963
     wallet->priv->session_credit_rules = FALSE;
1964
     wallet->priv->persistence_enabled = TRUE;
1965
 
1966
-    wallet_setup_consume_prices(wallet);
1967
     session_money = 0;
1968
     bonus_earned_money = 0;
1969
     displayed_bonus_credits= 0;
1970
@@ -4056,14 +3670,11 @@
1971
     wallet_class->add_free_credits              = wallet_add_free_credits_impl;
1972
     wallet_class->add_linked_credits            = wallet_add_linked_credits_impl;    
1973
     wallet_class->add_money                     = wallet_add_money_impl;
1974
-    wallet_class->consume_credits               = wallet_consume_credits_impl;
1975
-    wallet_class->consume_n_valued_credits      = wallet_consume_n_valued_credits_impl;
1976
     wallet_class->consume_n_credits             = wallet_consume_n_credits_impl;
1977
     wallet_class->transfer_credits_to_mytt_account = wallet_transfer_credits_to_mytt_account_impl;
1978
     wallet_class->flush_credits                 = wallet_flush_credits_impl;
1979
     wallet_class->is_in_session                 = wallet_is_in_session_impl;
1980
     wallet_class->stop_session                  = wallet_stop_session_impl;
1981
-    wallet_class->get_price                     = wallet_get_price_impl;
1982
     wallet_class->get_price_and_coinage         = wallet_get_price_and_coinage_impl;
1983
     wallet_class->set_cost                      = wallet_set_cost_impl;
1984
     wallet_class->get_cost                      = wallet_get_cost_impl;
1985
@@ -4495,32 +4106,77 @@
1986
     }
1987
 }
1988
 
1989
+static void
1990
+wallet_print_credits_used(CreditsUsedType type, guint value)
1991
+{
1992
+#ifdef DEBUG
1993
+    static const gchar *credits_used_names[] = {
1994
+        [ CREDITS_USED_PLAY ] = "play",
1995
+        [ CREDITS_USED_PLAYNOW ] = "playnow",
1996
+        [ CREDITS_USED_TC ] = "tc",
1997
+        [ CREDITS_USED_HOMEPROMO ] = "homepromo",
1998
+        [ CREDITS_USED_TRANSFER_TO_MYTT_ACCOUNT ] = "transfer-to-mytt-account",
1999
+    };
2000
 
2001
-static void wallet_save_credits_used( CreditsUsedType type,
2002
-                                      guint           value)
2003
+    G_STATIC_ASSERT(G_N_ELEMENTS(credits_used_names) == CREDITS_USED_SIZE);
2004
+
2005
+    g_print("Saved %u 'used credits' of type %s\n", value, credits_used_names[type]);
2006
+#endif
2007
+}
2008
+
2009
+static void
2010
+wallet_save_credits_used(CreditsUsedType type, guint value)
2011
 {
2012
-    Subject *s = chick_get_subject(DATA_BOOKKEEP_SAVE_CREDITS_USED);
2013
-    typevaluestruct *tv;
2014
-    if(s){
2015
-        tv = g_new0(typevaluestruct,1);
2016
-        tv->type = type;
2017
-        tv->value = value;
2018
-        subject_data_set_data_size(SUBJECTDATA(s), tv, sizeof(typevaluestruct));
2019
-        g_free(tv);
2020
+    Subject *subject = chick_get_subject(DATA_BOOKKEEP_SAVE_CREDITS_USED);
2021
+
2022
+    if (subject) {
2023
+        typevaluestruct tv = { 0, };
2024
+
2025
+        tv.type = type;
2026
+        tv.value = value;
2027
+
2028
+        subject_data_set_data_size(SUBJECTDATA(subject), &tv, sizeof(tv));
2029
+
2030
+        wallet_print_credits_used(type, value);
2031
+    } else {
2032
+        g_warning(G_STRLOC ": Failed to get subject '" DATA_BOOKKEEP_SAVE_CREDITS_USED "'");
2033
     }
2034
 }
2035
 
2036
-static void wallet_save_billing_split( BillingSplitType type,
2037
-                                       gfloat           value)
2038
+static void
2039
+wallet_print_billing_split(BillingSplitType type, gfloat value)
2040
 {
2041
-    Subject *s = chick_get_subject(DATA_BOOKKEEP_SAVE_SPLIT);
2042
-    typefloatstruct *tf;
2043
-    if(s){
2044
-        tf = g_new0(typefloatstruct,1);
2045
-        tf->type = type;
2046
-        tf->fvalue = value;
2047
-        subject_data_set_data_size(SUBJECTDATA(s), tf, sizeof(typefloatstruct));
2048
-        g_free(tf);
2049
+#ifdef DEBUG
2050
+    static const gchar *bs_names[] = {
2051
+        [ BS_JUKEBOX ] = "jukebox",
2052
+        [ BS_TC ] = "tc",
2053
+        [ BS_PLUGINS ] = "plugins",
2054
+        [ BS_MOBILE_LOCAL ] = "mobile-local",
2055
+        [ BS_MOBILE_TC ] = "mobile-tc",
2056
+    };
2057
+
2058
+    G_STATIC_ASSERT(G_N_ELEMENTS(bs_names) == BS_SIZE);
2059
+
2060
+    g_print("Saved %f for billing split of type %s\n", value, bs_names[type]);
2061
+#endif
2062
+}
2063
+
2064
+static void
2065
+wallet_save_billing_split(BillingSplitType type, gfloat value)
2066
+{
2067
+    Subject *subject = chick_get_subject(DATA_BOOKKEEP_SAVE_SPLIT);
2068
+
2069
+    if (subject) {
2070
+        typefloatstruct tf = { 0, };
2071
+
2072
+        tf.type = type;
2073
+        tf.fvalue = value;
2074
+
2075
+        subject_data_set_data_size(SUBJECTDATA(subject), &tf, sizeof(tf));
2076
+
2077
+        wallet_print_billing_split(type, value);
2078
+    } else {
2079
+        g_warning(G_STRLOC ": Failed to get subject '" DATA_BOOKKEEP_SAVE_SPLIT "'");
2080
     }
2081
 }
2082
 
Loading...