ADD_SUBDIRECTORY(src/server-dummy)
ADD_SUBDIRECTORY(src/client)
ADD_SUBDIRECTORY(src/server)
+ADD_SUBDIRECTORY(src/agent)
%manifest packaging/%{name}.manifest
%{_libdir}/lib%{name}-client-genuine.so.*
%{_libdir}/lib%{name}-server-genuine.so.*
+%{_libdir}/context-agent/*.so.*
%license LICENSE
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_AGENT_TYPES_H__
+#define __CONTEXT_AGENT_TYPES_H__
+
+#include <IAgentPlugin.h>
+
+#define AGENT_TYPE_GEOFENCE 1
+#define AGENT_TYPE_CONTACTS_DB 2
+
+#define GEOFENCE_CMD_START 1
+#define GEOFENCE_CMD_STOP 2
+#define GEOFENCE_SIGNAL "GeofenceInOut"
+
+#define CONTACTS_DB_CMD_START 1
+#define CONTACTS_DB_CMD_STOP 2
+#define CONTACTS_DB_SIGNAL "ContactsDbUpdated"
+
+#endif
--- /dev/null
+SET(target "${PROJECT_NAME}-agent")
+
+# Be sure that the agent so does not have dependency to context-common or job-scheduler itself.
+SET(DEPS "${DEPS} jsoncpp")
+SET(DEPS "${DEPS} capi-system-info")
+
+FILE(GLOB_RECURSE SRCS *.cpp)
+MESSAGE("Sources: ${SRCS}")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(PKG_AGENT REQUIRED ${DEPS})
+
+FOREACH(flag ${PKG_AGENT_CFLAGS})
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${target} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target} ${PKG_AGENT_LDFLAGS})
+SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
+
+INSTALL(TARGETS ${target} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/context-agent NAMELINK_SKIP)
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <ContextTypes.h>
+#include "AgentTypes.h"
+#include "ContactsDbAgent.h"
+
+using namespace ctx;
+
+ContactsDbAgent::ContactsDbAgent(IAgentUtil* agentUtil) :
+ __agentUtil(agentUtil)
+{
+ _D("Created");
+}
+
+ContactsDbAgent::~ContactsDbAgent()
+{
+ _D("Destroyed");
+}
+
+uint16_t ContactsDbAgent::getId()
+{
+ return CTX_AGENT_DOMAIN_JOB_SCHEDULER | AGENT_TYPE_CONTACTS_DB;
+}
+
+bool ContactsDbAgent::doAction(uint8_t length, const void* command)
+{
+ _D("Command: %d", reinterpret_cast<const char*>(command)[0]);
+
+ //TODO
+ // Regarding the given command, start or stop monitoring the DB changes.
+ // If a change is detected, send a signal to the ContactsDbChanges publisher.
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_JOB_SCHEDULER_CONTACTS_DB_AGENT_H__
+#define __CONTEXT_JOB_SCHEDULER_CONTACTS_DB_AGENT_H__
+
+#include <IAgentPlugin.h>
+
+namespace ctx {
+
+ class ContactsDbAgent : public IAgentPlugin {
+ public:
+ ContactsDbAgent(IAgentUtil* agentUtil);
+ ~ContactsDbAgent();
+
+ uint16_t getId();
+
+ bool doAction(uint8_t length, const void* command);
+
+ private:
+ IAgentUtil* __agentUtil;
+ };
+}
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <ContextTypes.h>
+#include "ContactsDbAgent.h"
+#include "GeofenceAgent.h"
+
+using namespace ctx;
+
+extern "C" EXPORT_API IAgentPlugin** CTX_AGENT_CREATE_FUNC(IAgentUtil* agentUtil)
+{
+ static IAgentPlugin* plugins[3];
+
+ plugins[0] = new ContactsDbAgent(agentUtil);
+ plugins[1] = new GeofenceAgent(agentUtil);
+ plugins[2] = NULL;
+
+ return plugins;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <ContextTypes.h>
+#include "AgentTypes.h"
+#include "GeofenceAgent.h"
+
+using namespace ctx;
+
+GeofenceAgent::GeofenceAgent(IAgentUtil* agentUtil) :
+ __agentUtil(agentUtil)
+{
+ _D("Created");
+}
+
+GeofenceAgent::~GeofenceAgent()
+{
+ _D("Destroyed");
+}
+
+uint16_t GeofenceAgent::getId()
+{
+ return CTX_AGENT_DOMAIN_JOB_SCHEDULER | AGENT_TYPE_GEOFENCE;
+}
+
+bool GeofenceAgent::doAction(uint8_t length, const void* command)
+{
+ _D("Command: %d", reinterpret_cast<const char*>(command)[0]);
+
+ //TODO
+ // Regarding the given command, start or stop monitoring Home/Work geofencing events.
+ // If an event is detected, send a signal to the GeofenceEvent publisher.
+ // This may require to assign an app id to this user session daemon,
+ // as the Geofence API requires the package id to distinguish a client.
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_JOB_SCHEDULER_GEOFENCE_AGENT_H__
+#define __CONTEXT_JOB_SCHEDULER_GEOFENCE_AGENT_H__
+
+#include <IAgentPlugin.h>
+
+namespace ctx {
+
+ class GeofenceAgent : public IAgentPlugin {
+ public:
+ GeofenceAgent(IAgentUtil* agentUtil);
+ ~GeofenceAgent();
+
+ uint16_t getId();
+
+ bool doAction(uint8_t length, const void* command);
+
+ private:
+ IAgentUtil* __agentUtil;
+ };
+}
+
+#endif
#include <regex>
#include <ContextTypes.h>
#include <SharedUtil.h>
+#include <ServerUtil.h>
#include "IContextObserver.h"
#include "ContextPublisher.h"
#include "publisher/CustomPublisher.h"
// Custom publishers
IF_FAIL_THROW(isCustomUri(uri), E_SUPPORT);
+ IF_FAIL_THROW(!util::is_system(uid), E_SUPPORT);
return new CustomPublisher(uri, uid);
}
bool JobManager::__isPermitted(const std::string& uri, IClient* client)
{
- if (ContextManager::isCustomUri(uri))
- return true;
-
ContextPublisher* pubs = ContextManager::getPublisher(uri, client->getUid());
IF_FAIL_RETURN(pubs, false);
IF_FAIL_RETURN(client->hasPrivilege(pubs->getPrivilege()), false);
g_variant_get(methodCall.getParam(), "(&s)", &uri);
IF_FAIL_THROW(uri, E_PARAM);
IF_FAIL_THROW(ContextManager::isCustomUri(uri), E_PARAM);
+ IF_FAIL_THROW(!methodCall.isSystem(), E_SUPPORT);
__getJobManager().addCustom(uri, __caller->getName());
g_variant_get(methodCall.getParam(), "(&s)", &uri);
IF_FAIL_THROW(uri, E_PARAM);
IF_FAIL_THROW(ContextManager::isCustomUri(uri), E_PARAM);
+ IF_FAIL_THROW(!methodCall.isSystem(), E_SUPPORT);
__getJobManager().removeCustom(uri, __caller->getName());
g_variant_get(methodCall.getParam(), "(&s&s)", &uri, &pkgId);
IF_FAIL_THROW(uri && pkgId, E_PARAM);
IF_FAIL_THROW(ContextManager::isCustomUri(uri), E_PARAM);
+ IF_FAIL_THROW(!methodCall.isSystem(), E_SUPPORT);
bool exist = __getJobManager().checkCustom(uri, pkgId);
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <system_info.h>
+
+#include <ContextTypes.h>
+#include <AgentCommander.h>
+#include <DBusMonitor.h>
+#include <IDBusSignalListener.h>
+
+#include <JobSchedulerTypesPrivate.h>
+#include <job_scheduler_types_internal.h>
+#include "../../agent/AgentTypes.h"
+#include "../ContextPublisher.h"
+#include "../IContextObserver.h"
+
+using namespace ctx;
+
+namespace {
+ class GeofenceEvent : public ContextPublisher, public IDBusSignalListener {
+ public:
+ GeofenceEvent(uid_t uid);
+ ~GeofenceEvent();
+
+ const char* getUri() const;
+
+ bool isReadable() const;
+
+ protected:
+ void read();
+ void subscribe();
+ void unsubscribe();
+
+ void onSignal(const std::string& sender, const std::string& objPath,
+ const std::string& interface, const std::string& signalName,
+ GVariant* param);
+
+ private:
+ uid_t __uid;
+ unsigned int __signalId;
+ DBusMonitor __dbusMonitor;
+ };
+}
+
+REGISTER_PUBLISHER(URI(GEOFENCE), GeofenceEvent)
+
+GeofenceEvent::GeofenceEvent(uid_t uid) :
+ __uid(uid),
+ __signalId(0)
+{
+ bool supported = false;
+ system_info_get_platform_bool("tizen.org/feature/location.geofence", &supported);
+ IF_FAIL_THROW(supported, E_SUPPORT);
+
+ _D("Created");
+}
+
+GeofenceEvent::~GeofenceEvent()
+{
+ unsubscribe();
+
+ _D("Destroyed");
+}
+
+const char* GeofenceEvent::getUri() const
+{
+ return URI(GEOFENCE);
+}
+
+bool GeofenceEvent::isReadable() const
+{
+ return false;
+}
+
+void GeofenceEvent::read()
+{
+}
+
+void GeofenceEvent::subscribe()
+{
+ const char cmd = GEOFENCE_CMD_START;
+
+ AgentCommander commander(__uid);
+ bool success = commander.send(CTX_AGENT_DOMAIN_JOB_SCHEDULER | AGENT_TYPE_GEOFENCE, sizeof(cmd), &cmd);
+ IF_FAIL_VOID_TAG(success, _E, "Sending command failed");
+
+ __signalId = __dbusMonitor.subscribe(NULL,
+ CTX_DBUS_PATH "/" CTX_JOB_SCHEDULER,
+ CTX_DBUS_IFACE "." CTX_JOB_SCHEDULER,
+ GEOFENCE_SIGNAL, this);
+}
+
+void GeofenceEvent::unsubscribe()
+{
+ const char cmd = GEOFENCE_CMD_STOP;
+
+ __dbusMonitor.unsubscribe(__signalId);
+
+ AgentCommander commander(__uid);
+ bool success = commander.send(CTX_AGENT_DOMAIN_JOB_SCHEDULER | AGENT_TYPE_GEOFENCE, sizeof(cmd), &cmd);
+ IF_FAIL_VOID_TAG(success, _E, "Sending command failed");
+}
+
+void GeofenceEvent::onSignal(const std::string& sender,
+ const std::string& objPath, const std::string& interface,
+ const std::string& signalName, GVariant* param)
+{
+ // TODO
+}