@@ -30,6 +30,9 @@ _mongoc_write_concern_warn_frozen (mongoc_write_concern_t *write_concern)
30
30
return write_concern -> frozen ;
31
31
}
32
32
33
+ static void
34
+ _mongoc_write_concern_freeze (mongoc_write_concern_t * write_concern );
35
+
33
36
34
37
/**
35
38
* mongoc_write_concern_new:
@@ -82,6 +85,7 @@ mongoc_write_concern_destroy (mongoc_write_concern_t *write_concern)
82
85
if (write_concern ) {
83
86
if (write_concern -> compiled .len ) {
84
87
bson_destroy (& write_concern -> compiled );
88
+ bson_destroy (& write_concern -> compiled_gle );
85
89
}
86
90
87
91
bson_free (write_concern -> wtag );
@@ -261,62 +265,104 @@ mongoc_write_concern_set_wtag (mongoc_write_concern_t *write_concern,
261
265
}
262
266
}
263
267
268
+ /**
269
+ * mongoc_write_concern_get_bson:
270
+ * @write_concern: A mongoc_write_concern_t.
271
+ *
272
+ * This is an internal function.
273
+ *
274
+ * Freeze the write concern if necessary and retrieve the encoded bson_t
275
+ * representing the write concern.
276
+ *
277
+ * You may not modify the write concern further after calling this function.
278
+ *
279
+ * Returns: A bson_t that should not be modified or freed as it is owned by
280
+ * the mongoc_write_concern_t instance.
281
+ */
282
+ const bson_t *
283
+ _mongoc_write_concern_get_bson (mongoc_write_concern_t * write_concern ) {
284
+ if (!write_concern -> frozen ) {
285
+ _mongoc_write_concern_freeze (write_concern );
286
+ }
287
+
288
+ return & write_concern -> compiled ;
289
+ }
264
290
265
291
/**
266
- * mongoc_write_concern_freeze :
292
+ * mongoc_write_concern_get_gle :
267
293
* @write_concern: A mongoc_write_concern_t.
268
294
*
269
295
* This is an internal function.
270
296
*
271
- * Freeze the write concern if necessary and compile the getlasterror command
272
- * associated with it .
297
+ * Freeze the write concern if necessary and retrieve the encoded bson_t
298
+ * representing the write concern as a get last error command .
273
299
*
274
300
* You may not modify the write concern further after calling this function.
275
301
*
276
302
* Returns: A bson_t that should not be modified or freed as it is owned by
277
303
* the mongoc_write_concern_t instance.
278
304
*/
279
305
const bson_t *
306
+ _mongoc_write_concern_get_gle (mongoc_write_concern_t * write_concern ) {
307
+ if (!write_concern -> frozen ) {
308
+ _mongoc_write_concern_freeze (write_concern );
309
+ }
310
+
311
+ return & write_concern -> compiled_gle ;
312
+ }
313
+
314
+ /**
315
+ * mongoc_write_concern_freeze:
316
+ * @write_concern: A mongoc_write_concern_t.
317
+ *
318
+ * This is an internal function.
319
+ *
320
+ * Freeze the write concern if necessary and encode it into a bson_ts which
321
+ * represent the raw bson form and the get last error command form.
322
+ *
323
+ * You may not modify the write concern further after calling this function.
324
+ */
325
+ static void
280
326
_mongoc_write_concern_freeze (mongoc_write_concern_t * write_concern )
281
327
{
282
- bson_t * b ;
328
+ bson_t * compiled ;
329
+ bson_t * compiled_gle ;
283
330
284
331
bson_return_val_if_fail (write_concern , NULL );
285
332
286
- b = & write_concern -> compiled ;
333
+ compiled = & write_concern -> compiled ;
334
+ compiled_gle = & write_concern -> compiled_gle ;
287
335
288
- if (!write_concern -> frozen ) {
289
- write_concern -> frozen = true;
290
-
291
- bson_init (b );
336
+ write_concern -> frozen = true;
292
337
293
- BSON_APPEND_INT32 (b , "getlasterror" , 1 );
338
+ bson_init (compiled );
339
+ bson_init (compiled_gle );
294
340
295
- if (write_concern -> w == MONGOC_WRITE_CONCERN_W_TAG ) {
296
- BSON_ASSERT (write_concern -> wtag );
297
- BSON_APPEND_UTF8 (b , "w" , write_concern -> wtag );
298
- } else if (write_concern -> w == MONGOC_WRITE_CONCERN_W_MAJORITY ) {
299
- BSON_APPEND_UTF8 (b , "w" , "majority" );
300
- } else if (write_concern -> w == MONGOC_WRITE_CONCERN_W_DEFAULT ) {
301
- /* Do Nothing */
302
- } else if (write_concern -> w > 0 ) {
303
- BSON_APPEND_INT32 (b , "w" , write_concern -> w );
304
- }
341
+ if (write_concern -> w == MONGOC_WRITE_CONCERN_W_TAG ) {
342
+ BSON_ASSERT (write_concern -> wtag );
343
+ BSON_APPEND_UTF8 (compiled , "w" , write_concern -> wtag );
344
+ } else if (write_concern -> w == MONGOC_WRITE_CONCERN_W_MAJORITY ) {
345
+ BSON_APPEND_UTF8 (compiled , "w" , "majority" );
346
+ } else if (write_concern -> w == MONGOC_WRITE_CONCERN_W_DEFAULT ) {
347
+ /* Do Nothing */
348
+ } else if (write_concern -> w > 0 ) {
349
+ BSON_APPEND_INT32 (compiled , "w" , write_concern -> w );
350
+ }
305
351
306
- if (write_concern -> fsync_ ) {
307
- bson_append_bool (b , "fsync" , 5 , true);
308
- }
352
+ if (write_concern -> fsync_ ) {
353
+ bson_append_bool (compiled , "fsync" , 5 , true);
354
+ }
309
355
310
- if (write_concern -> journal ) {
311
- bson_append_bool (b , "j" , 1 , true);
312
- }
356
+ if (write_concern -> journal ) {
357
+ bson_append_bool (compiled , "j" , 1 , true);
358
+ }
313
359
314
- if (write_concern -> wtimeout ) {
315
- bson_append_int32 (b , "wtimeout" , 8 , write_concern -> wtimeout );
316
- }
360
+ if (write_concern -> wtimeout ) {
361
+ bson_append_int32 (compiled , "wtimeout" , 8 , write_concern -> wtimeout );
317
362
}
318
363
319
- return b ;
364
+ BSON_APPEND_INT32 (compiled_gle , "getlasterror" , 1 );
365
+ bson_concat (compiled_gle , compiled );
320
366
}
321
367
322
368
0 commit comments