1
+ /*
2
+ * Copyright 2018-2020 ObjectBox Ltd. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #include " tasklist-example-app.hpp"
18
+
19
+ #include " objectbox-sync.hpp"
20
+
21
+ using namespace obx ;
22
+
23
+ int main (int argc, char * argv[]) {
24
+ // this example expect sync-server to be running locally
25
+ std::string syncServerURL = " ws://127.0.0.1:9999" ;
26
+
27
+ std::cout << " This is a simple example of a ObjectBox Sync client application." << std::endl
28
+ << " To execute this example yourself, you need to start a sync-server locally:" << std::endl
29
+ << " ./sync-server --model objectbox-model.json -d server-db --unsecured-no-authentication"
30
+ << " --bind " + syncServerURL << std::endl
31
+ << " Note: update the --model argument path to the model file from this example directory." << std::endl
32
+ << " You can launch multiple instances of this program in parallel in two windows, each with" << std::endl
33
+ << " a separate database by starting each with a different `--directory dirname` argument." << std::endl
34
+ << " The clients automatically connect to the sync-server (URL specified in main-sync.cpp)." << std::endl
35
+ << " See sync in action: create tasks on one client and refresh the list on the other." << std::endl;
36
+ std::cout << " ---------------------------------------------------------------------------------------" << std::endl;
37
+
38
+ // create_obx_model() provided by objectbox-model.h
39
+ // obx interface contents provided by objectbox.hpp
40
+ Store::Options storeOptions (create_obx_model ());
41
+
42
+ if (int err = processArgs (argc, argv, storeOptions)) {
43
+ return err;
44
+ }
45
+
46
+ Store store (storeOptions);
47
+
48
+ // Note: server is expected to be set up with no authentication for this demo
49
+ std::shared_ptr<SyncClient> client = Sync::client (store, syncServerURL, SyncCredentials::none ());
50
+ client->start ();
51
+
52
+ TasklistCmdlineApp app (store);
53
+ return app.run ();
54
+ }
0 commit comments