2 // This is just experimentation code to figure out the config API in 0.4x
5 // g++ -Wall -o oextract oextract.cc $(pkg-config --cflags --libs libopensync1)
10 #include <opensync/opensync.h>
11 #include <opensync/opensync-plugin.h>
12 #include <opensync/opensync-group.h>
15 #define NP(x) (x ? x : "(null)")
20 void get_advanced(OSyncPluginConfig
*config
, const char *name
)
22 cout
<< "Advanced: " << name
<< ": "
23 << NP(osync_plugin_config_get_advancedoption_value_by_name(config
, name
))
27 void add_advanced(OSyncPluginConfig
*config
,
32 OSyncError
*ose
= NULL
;
33 OSyncPluginAdvancedOption
*option
= osync_plugin_advancedoption_new(&ose
);
34 if( !option
) throw "bad option";
35 osync_plugin_advancedoption_set_displayname(option
, "Test Display Name");
36 osync_plugin_advancedoption_set_name(option
, "TestName");
37 osync_plugin_advancedoption_set_type(option
, OSYNC_PLUGIN_ADVANCEDOPTION_TYPE_STRING
);
38 osync_plugin_advancedoption_set_value(option
, "Whippoorwill");
39 osync_plugin_config_add_advancedoption(config
, option
);
40 osync_plugin_advancedoption_unref(option
);
43 void dump_resource(OSyncPluginResource
*res
)
46 << NP(osync_plugin_resource_get_name(res
))
48 << (osync_plugin_resource_is_enabled(res
) ? "enabled" : "disabled");
49 if( osync_plugin_resource_get_preferred_format(res
) )
50 cout
<< "\n pref format: "
51 << osync_plugin_resource_get_preferred_format(res
);
53 if( osync_plugin_resource_get_mime(res
) )
55 << NP(osync_plugin_resource_get_mime(res
));
57 if( osync_plugin_resource_get_objtype(res
) )
58 cout
<< "\n objtype: "
59 << NP(osync_plugin_resource_get_objtype(res
));
61 if( osync_plugin_resource_get_path(res
) )
63 << NP(osync_plugin_resource_get_path(res
));
65 if( osync_plugin_resource_get_url(res
) )
67 << NP(osync_plugin_resource_get_url(res
));
68 osync_plugin_resource_set_url(res
, "http://whoopiecushion/");
73 void dump_resources(OSyncPluginConfig
*config
)
75 OSyncList
*resources
= osync_plugin_config_get_resources(config
);
76 for( OSyncList
*o
= resources
; o
; o
= o
->next
) {
77 OSyncPluginResource
*res
= (OSyncPluginResource
*) o
->data
;
82 void test_member(OSyncGroup
*group
, int member_id
)
84 OSyncError
*ose
= NULL
;
86 cout
<< "Testing member: " << member_id
<< endl
;
88 OSyncMember
*member
= osync_group_find_member(group
, member_id
);
89 if( !member
) throw "bad member id";
90 OSyncPlugin
*plugin
= osync_plugin_env_find_plugin(penv
, osync_member_get_pluginname(member
));
91 if( !plugin
) throw "bad plugin";
92 OSyncPluginConfig
*config
= osync_member_get_config_or_default(member
, &ose
);
93 if( !config
) throw "bad config";
95 // extract advanced fields
96 get_advanced(config
, "PinCode");
97 get_advanced(config
, "Debug");
100 add_advanced(config
, "TestName", "Test Display Name", "Whippoorwill");
101 get_advanced(config
, "TestName");
104 dump_resources(config
);
107 if( !osync_member_save(member
, &ose
) )
108 throw "bad member save";
110 // due to leak in library, I don't think this is safe to call?
111 //osync_plugin_config_unref(config);
116 OSyncError
*ose
= NULL
;
119 genv
= osync_group_env_new(&ose
);
120 if( !genv
) throw "bad genv";
121 penv
= osync_plugin_env_new(&ose
);
122 if( !penv
) throw "bad penv";
125 if( !osync_group_env_load_groups(genv
, NULL
, &ose
) )
126 throw "bad group load";
127 if( !osync_plugin_env_load(penv
, NULL
, &ose
) )
128 throw "bad plugin load";
131 OSyncGroup
*group
= osync_group_env_find_group(genv
, "test");
132 if( !group
) throw "bad group";
133 test_member(group
, 1);
134 test_member(group
, 2);
137 osync_plugin_env_unref(penv
);
138 osync_group_env_unref(genv
);
144 catch( const char *msg
) {
145 cout
<< "Exception: " << msg
<< endl
;