int ctx_sched_job_set_disjunction(ctx_sched_job_h job, bool disjunction);
int ctx_sched_job_context_set_disjunction(ctx_sched_job_context_h job_context, bool disjunction);
+// Custom context registration functions to support legacy Context-Trigger API.
+int ctx_sched_custom_register(ctx_sched_h scheduler, const char* uri);
+int ctx_sched_custom_unregister(ctx_sched_h scheduler, const char* uri);
+int ctx_sched_custom_is_registered(ctx_sched_h scheduler, const char* uri, const char* pkg_id, bool* registered);
+
/**
* @}
{
return E_SUPPORT;
}
+
+EXPORT_API int ctx_sched_custom_register(ctx_sched_h scheduler, const char* uri)
+{
+ return E_SUPPORT;
+}
+
+EXPORT_API int ctx_sched_custom_unregister(ctx_sched_h scheduler, const char* uri)
+{
+ return E_SUPPORT;
+}
+
+EXPORT_API int ctx_sched_custom_is_registered(ctx_sched_h scheduler, const char* uri, const char* pkg_id, bool* registered)
+{
+ return E_SUPPORT;
+}
return __serviceProxy.call(METHOD_PUBLISH_CONTEXT, g_variant_new("(ss)", uri.c_str(), payload.c_str()));
}
+int JobManagerProxy::registerCustom(const std::string& uri)
+{
+ return __serviceProxy.call(METHOD_REGISTER_CUSTOM, g_variant_new("(s)", uri.c_str()));
+}
+
+int JobManagerProxy::unregisterCustom(const std::string& uri)
+{
+ return __serviceProxy.call(METHOD_UNREGISTER_CUSTOM, g_variant_new("(s)", uri.c_str()));
+}
+
+bool JobManagerProxy::isRegisteredCustom(const std::string& uri, const std::string& pkgId)
+{
+ int error= __serviceProxy.call(METHOD_IS_REGISTERED_CUSTOM, g_variant_new("(ss)", uri.c_str(), pkgId.c_str()));
+ return IS_SUCCESS(error);
+}
+
bool JobManagerProxy::__isAvailable(int type, const std::string& uri)
{
GVariant* param = g_variant_new("(is)", type, uri.c_str());
int publishContext(const std::string& uri, const std::string& payload);
+ // For supporting Context-Trigger APIs. These functions does not affect publishContext().
+ int registerCustom(const std::string& uri);
+ int unregisterCustom(const std::string& uri);
+ bool isRegisteredCustom(const std::string& uri, const std::string& pkgId);
+
private:
bool __isAvailable(int type, const std::string& uri);
void __onStartJob(GVariant* param);
return E_NONE;
}
+
+EXPORT_API int ctx_sched_custom_register(ctx_sched_h scheduler, const char* uri)
+{
+ IF_FAIL_RETURN(scheduler && uri, E_PARAM);
+
+ return scheduler->jobManager.registerCustom(uri);
+}
+
+EXPORT_API int ctx_sched_custom_unregister(ctx_sched_h scheduler, const char* uri)
+{
+ IF_FAIL_RETURN(scheduler && uri, E_PARAM);
+
+ return scheduler->jobManager.unregisterCustom(uri);
+}
+
+EXPORT_API int ctx_sched_custom_is_registered(ctx_sched_h scheduler, const char* uri, const char* pkg_id, bool* registered)
+{
+ IF_FAIL_RETURN(scheduler && uri && pkg_id && registered, E_PARAM);
+
+ *registered = scheduler->jobManager.isRegisteredCustom(uri, pkg_id);
+
+ return E_NONE;
+}
#include "ContextPublisher.h"
#include "publisher/CustomPublisher.h"
-#define CUSTOM_URI_REGEX R"~(^http:\/\/[\w-\.]+\/context\/custom\/[\w-\._]+$)~"
+#define CUSTOM_URI_REGEX R"~(^http:\/\/[\w-\.]+\/context\/custom\/[\w-\._\/]+$)~"
using namespace ctx;
return jobInfos;
}
+void JobManager::addCustom(const std::string& uri, const std::string& ownerId)
+{
+ std::string key = uri + "@" + ownerId;
+ _D("%s", key.c_str());
+ __registeredCustoms.insert(key);
+}
+
+void JobManager::removeCustom(const std::string& uri, const std::string& ownerId)
+{
+ std::string key = uri + "@" + ownerId;
+ _D("%s", key.c_str());
+ __registeredCustoms.erase(key);
+}
+
+bool JobManager::checkCustom(const std::string& uri, const std::string& ownerId)
+{
+ std::string key = uri + "@" + ownerId;
+ _D("%s", key.c_str());
+ return (__registeredCustoms.find(key) != __registeredCustoms.end());
+}
+
JobInfo* JobManager::__getDuplicate(const std::string& ownerId, JobInfo* target)
{
for (auto* runner : __jobRunners) {
#define __CONTEXT_JOB_SCHEDULER_JOB_MANAGER_H__
#include <list>
+#include <set>
#include <JobInfo.h>
#include <JobContext.h>
#include <IClient.h>
JobInfo* getJobInfo(int jobId, IClient* owner);
std::vector<JobInfo*> getAllJobInfo(IClient* owner);
+ // For supporting Context-Trigger's custom context registration APIs
+ void addCustom(const std::string& uri, const std::string& ownerId);
+ void removeCustom(const std::string& uri, const std::string& ownerId);
+ bool checkCustom(const std::string& uri, const std::string& ownerId);
+
private:
int __addPeriodicJob(PeriodicJobInfo* jobInfo, IClient* owner);
int __addOnDemandJob(OnDemandJobInfo* jobInfo, IClient* owner);
std::list<JobRunner*> __jobRunners;
JobInfoDatabase __jobInfoDatabase;
+
+ // For supporting Context-Trigger's custom context registration APIs
+ std::set<std::string> __registeredCustoms;
};
}
} else if (methodCall->getMethodName() == METHOD_PUBLISH_CONTEXT) {
__publishContext(*methodCall);
+
+ } else if (methodCall->getMethodName() == METHOD_REGISTER_CUSTOM) {
+ __registerCustom(*methodCall);
+
+ } else if (methodCall->getMethodName() == METHOD_UNREGISTER_CUSTOM) {
+ __unregisterCustom(*methodCall);
+
+ } else if (methodCall->getMethodName() == METHOD_IS_REGISTERED_CUSTOM) {
+ __isRegisteredCustom(*methodCall);
}
} catch (const int error) {
_W("Catch: %s", CTX_ERROR_STR(error));
pubs->putData(data);
}
+
+void MethodCallHandler::__registerCustom(IMethodCall& methodCall)
+{
+ const char* uri = NULL;
+
+ g_variant_get(methodCall.getParam(), "(&s)", &uri);
+ IF_FAIL_THROW(uri, E_PARAM);
+ IF_FAIL_THROW(ContextManager::isCustomUri(uri), E_PARAM);
+
+ __getJobManager().addCustom(uri, __caller->getName());
+
+ methodCall.reply(E_NONE);
+}
+
+void MethodCallHandler::__unregisterCustom(IMethodCall& methodCall)
+{
+ const char* uri = NULL;
+
+ g_variant_get(methodCall.getParam(), "(&s)", &uri);
+ IF_FAIL_THROW(uri, E_PARAM);
+ IF_FAIL_THROW(ContextManager::isCustomUri(uri), E_PARAM);
+
+ __getJobManager().removeCustom(uri, __caller->getName());
+
+ methodCall.reply(E_NONE);
+}
+
+void MethodCallHandler::__isRegisteredCustom(IMethodCall& methodCall)
+{
+ const char* uri = NULL;
+ const char* pkgId = NULL;
+
+ g_variant_get(methodCall.getParam(), "(&s&s)", &uri, &pkgId);
+ IF_FAIL_THROW(uri && pkgId, E_PARAM);
+ IF_FAIL_THROW(ContextManager::isCustomUri(uri), E_PARAM);
+
+ bool exist = __getJobManager().checkCustom(uri, pkgId);
+
+ methodCall.reply(exist ? E_NONE : E_NO_DATA);
+}
JobManager& __getJobManager();
void __isSupported(IMethodCall& methodCall);
+
void __addJob(IMethodCall& methodCall);
void __startJob(IMethodCall& methodCall);
void __stopJob(IMethodCall& methodCall);
void __removeJob(IMethodCall& methodCall);
+
void __jobFinished(IMethodCall& methodCall);
+
void __getJob(IMethodCall& methodCall);
void __getAllJob(IMethodCall& methodCall);
+
void __enableLifecycleCallbacks(IMethodCall& methodCall);
void __publishContext(IMethodCall& methodCall);
+ void __registerCustom(IMethodCall& methodCall);
+ void __unregisterCustom(IMethodCall& methodCall);
+ void __isRegisteredCustom(IMethodCall& methodCall);
+
IClient* __caller;
bool __callbackEnabled;
};
"<method name='" METHOD_PUBLISH_CONTEXT "'>" \
" <arg type='s' name='uri' direction='in'/>" \
" <arg type='s' name='payload' direction='in'/>" \
+ "</method>" \
+ "<method name='" METHOD_REGISTER_CUSTOM "'>" \
+ " <arg type='s' name='uri' direction='in'/>" \
+ "</method>" \
+ "<method name='" METHOD_UNREGISTER_CUSTOM "'>" \
+ " <arg type='s' name='uri' direction='in'/>" \
+ "</method>" \
+ "<method name='" METHOD_IS_REGISTERED_CUSTOM "'>" \
+ " <arg type='s' name='uri' direction='in'/>" \
+ " <arg type='s' name='pkgId' direction='in'/>" \
"</method>"
#define METHOD_ADD_JOB "AddJob"
#define METHOD_IS_SUPPORTED "IsSupported"
#define METHOD_ENABLE_CB "EnableCb"
#define METHOD_PUBLISH_CONTEXT "PublishContext"
+#define METHOD_REGISTER_CUSTOM "RegisterCustom"
+#define METHOD_UNREGISTER_CUSTOM "UnregisterCustom"
+#define METHOD_IS_REGISTERED_CUSTOM "IsRegisteredCustom"
#define SIGNAL_START_JOB "JobStarted"
#define SIGNAL_STOP_JOB "JobToBeStopped"