Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the user to specify sync mode on an instance
Change-Id: Ibe6bbcece6f8ebb67a6b38fb1bbc5fb9baafdf1e Reviewed-on: http://review.couchbase.org/12560 Tested-by: Trond Norbye <trond.norbye@gmail.com> Reviewed-by: Matt Ingenthron <matt@couchbase.com>
- Loading branch information
Showing
16 changed files
with
185 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Copyright 2012 Couchbase, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef LIBCOUCHBASE_BEHAVIOR_H | ||
#define LIBCOUCHBASE_BEHAVIOR_H 1 | ||
|
||
#ifndef LIBCOUCHBASE_COUCHBASE_H | ||
#error "Include libcouchbase/couchbase.h instead" | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
LIBCOUCHBASE_API | ||
void libcouchbase_behavior_set_syncmode(libcouchbase_t instance, | ||
libcouchbase_syncmode_t syncmode); | ||
|
||
LIBCOUCHBASE_API | ||
libcouchbase_syncmode_t libcouchbase_behavior_get_syncmode(libcouchbase_t instance); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Copyright 2012 Couchbase, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "internal.h" | ||
|
||
LIBCOUCHBASE_API | ||
void libcouchbase_behavior_set_syncmode(libcouchbase_t instance, libcouchbase_syncmode_t syncmode) | ||
{ | ||
instance->syncmode = syncmode; | ||
} | ||
|
||
LIBCOUCHBASE_API | ||
libcouchbase_syncmode_t libcouchbase_behavior_get_syncmode(libcouchbase_t instance) | ||
{ | ||
return instance->syncmode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
/* | ||
* Copyright 2012 Couchbase, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "internal.h" | ||
|
||
struct user_cookie { | ||
void *cookie; | ||
libcouchbase_error_callback error; | ||
libcouchbase_error_t retcode; | ||
}; | ||
|
||
|
||
static void error_callback(libcouchbase_t instance, | ||
libcouchbase_error_t error, | ||
const char *errinfo) | ||
{ | ||
struct user_cookie *cookie = (void*)instance->cookie; | ||
if (error == LIBCOUCHBASE_SUCCESS) { | ||
return ; | ||
} | ||
|
||
/* Restore the users environment */ | ||
instance->cookie = cookie->cookie; | ||
instance->callbacks.error = cookie->error; | ||
|
||
/* Call the user's callback */ | ||
cookie->error(instance, error, errinfo); | ||
|
||
/* Restore the wrapping environment */ | ||
cookie->error = instance->callbacks.error; /* User might have changed this */ | ||
instance->cookie = cookie; | ||
|
||
/* Save the error code */ | ||
cookie->retcode = error; | ||
|
||
/* Ok, stop the event loop */ | ||
instance->io->stop_event_loop(instance->io); | ||
} | ||
|
||
libcouchbase_error_t libcouchbase_synchandler_return(libcouchbase_t instance, libcouchbase_error_t retcode) | ||
{ | ||
struct user_cookie cookie; | ||
|
||
if (instance->syncmode == LIBCOUCHBASE_ASYNCHRONOUS || | ||
retcode != LIBCOUCHBASE_SUCCESS) { | ||
return retcode; | ||
} | ||
|
||
cookie.retcode = LIBCOUCHBASE_SUCCESS; | ||
|
||
/* Save the users environment */ | ||
cookie.error = instance->callbacks.error; | ||
cookie.cookie = (void*)instance->cookie; | ||
instance->cookie = &cookie; | ||
|
||
libcouchbase_wait(instance); | ||
/* Restore the environment */ | ||
instance->callbacks.error = cookie.error; | ||
instance->cookie = cookie.cookie; | ||
|
||
return cookie.retcode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters