00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "opensync.h"
00022 #include "opensync_internals.h"
00023
00024 #include "opensync-format.h"
00025 #include "opensync-plugin.h"
00026 #include "opensync_plugin_resource_private.h"
00027
00028 OSyncPluginResource *osync_plugin_resource_new(OSyncError **error)
00029 {
00030 OSyncPluginResource *resource = osync_try_malloc0(sizeof(OSyncPluginResource), error);
00031 if (!resource)
00032 return NULL;
00033
00034 resource->ref_count = 1;
00035
00036 return resource;
00037 }
00038
00039 OSyncPluginResource *osync_plugin_resource_ref(OSyncPluginResource *resource)
00040 {
00041 osync_assert(resource);
00042
00043 g_atomic_int_inc(&(resource->ref_count));
00044
00045 return resource;
00046 }
00047
00048 void osync_plugin_resource_unref(OSyncPluginResource *resource)
00049 {
00050 osync_assert(resource);
00051
00052 if (g_atomic_int_dec_and_test(&(resource->ref_count))) {
00053 if (resource->name)
00054 osync_free(resource->name);
00055
00056 if (resource->objtype)
00057 osync_free(resource->objtype);
00058
00059 if (resource->mime)
00060 osync_free(resource->mime);
00061
00062 while (resource->objformatsinks) {
00063 osync_objformat_sink_unref(resource->objformatsinks->data);
00064 resource->objformatsinks = osync_list_remove(resource->objformatsinks, resource->objformatsinks->data);
00065 }
00066
00067 if (resource->path)
00068 osync_free(resource->path);
00069
00070 if (resource->url)
00071 osync_free(resource->url);
00072
00073 osync_free(resource);
00074 }
00075 }
00076
00077 osync_bool osync_plugin_resource_option_is_supported(OSyncPluginResource *resource, OSyncPluginResourceOptionSupportedFlag flag)
00078 {
00079 osync_assert(resource);
00080 if (resource->supported_options & flag)
00081 return TRUE;
00082
00083 return FALSE;
00084 }
00085
00086 void osync_plugin_resource_option_set_supported(OSyncPluginResource *resource, OSyncPluginResourceOptionSupportedFlags flags)
00087 {
00088 osync_assert(resource);
00089 resource->supported_options = flags;
00090 }
00091
00092 osync_bool osync_plugin_resource_is_enabled(OSyncPluginResource *resource)
00093 {
00094 osync_assert(resource);
00095 return resource->enabled;
00096 }
00097
00098 void osync_plugin_resource_enable(OSyncPluginResource *resource, osync_bool enable)
00099 {
00100 osync_assert(resource);
00101 resource->enabled = enable;
00102 }
00103
00104 const char *osync_plugin_resource_get_name(OSyncPluginResource *resource)
00105 {
00106 osync_assert(resource);
00107 return resource->name;
00108 }
00109
00110 void osync_plugin_resource_set_name(OSyncPluginResource *resource, const char *name)
00111 {
00112 osync_assert(resource);
00113 if (resource->name)
00114 osync_free(resource->name);
00115
00116 resource->name = osync_strdup(name);
00117 }
00118
00119 const char *osync_plugin_resource_get_mime(OSyncPluginResource *resource)
00120 {
00121 osync_assert(resource);
00122 return resource->mime;
00123 }
00124
00125 void osync_plugin_resource_set_mime(OSyncPluginResource *resource, const char *mime)
00126 {
00127 osync_assert(resource);
00128 if (resource->mime)
00129 osync_free(resource->mime);
00130
00131 resource->mime = osync_strdup(mime);
00132 }
00133
00134 const char *osync_plugin_resource_get_preferred_format(OSyncPluginResource *resource)
00135 {
00136 osync_assert(resource);
00137 return resource->preferred_format;
00138 }
00139
00140 void osync_plugin_resource_set_preferred_format(OSyncPluginResource *resource, const char *preferred_format)
00141 {
00142 osync_assert(resource);
00143 if (resource->preferred_format)
00144 osync_free(resource->preferred_format);
00145
00146 resource->preferred_format = osync_strdup(preferred_format);
00147 }
00148
00149 OSyncList *osync_plugin_resource_get_objformat_sinks(OSyncPluginResource *resource)
00150 {
00151 osync_assert(resource);
00152 return resource->objformatsinks;
00153 }
00154
00155 void osync_plugin_resource_add_objformat_sink(OSyncPluginResource *resource, OSyncObjFormatSink *formatsink)
00156 {
00157 osync_assert(resource);
00158 osync_assert(formatsink);
00159
00160 if (osync_list_find(resource->objformatsinks, formatsink))
00161 return;
00162
00163 osync_objformat_sink_ref(formatsink);
00164 resource->objformatsinks = osync_list_prepend(resource->objformatsinks, formatsink);
00165 }
00166
00167 void osync_plugin_resource_remove_objformat_sink(OSyncPluginResource *resource, OSyncObjFormatSink *formatsink)
00168 {
00169 osync_assert(resource);
00170 osync_assert(formatsink);
00171
00172 resource->objformatsinks = osync_list_remove(resource->objformatsinks, formatsink);
00173 osync_objformat_sink_unref(formatsink);
00174 }
00175
00176 const char *osync_plugin_resource_get_objtype(OSyncPluginResource *resource)
00177 {
00178 osync_assert(resource);
00179 return resource->objtype;
00180 }
00181
00182 void osync_plugin_resource_set_objtype(OSyncPluginResource *resource, const char *objtype)
00183 {
00184 osync_assert(resource);
00185 if (resource->objtype)
00186 osync_free(resource->objtype);
00187
00188 resource->objtype = osync_strdup(objtype);
00189 }
00190
00191 const char *osync_plugin_resource_get_path(OSyncPluginResource *resource)
00192 {
00193 osync_assert(resource);
00194 return resource->path;
00195 }
00196
00197 void osync_plugin_resource_set_path(OSyncPluginResource *resource, const char *path)
00198 {
00199 osync_assert(resource);
00200 if (resource->path)
00201 osync_free(resource->path);
00202
00203 resource->path = osync_strdup(path);
00204 }
00205
00206 const char *osync_plugin_resource_get_url(OSyncPluginResource *resource)
00207 {
00208 osync_assert(resource);
00209 return resource->url;
00210 }
00211
00212 void osync_plugin_resource_set_url(OSyncPluginResource *resource, const char *url)
00213 {
00214 osync_assert(resource);
00215 if (resource->url)
00216 osync_free(resource->url);
00217
00218 resource->url = osync_strdup(url);
00219 }
00220