Add skeletons of the user-session agents 80/141280/4
authorMu-Woong Lee <muwoong.lee@samsung.com>
Sun, 30 Jul 2017 09:01:34 +0000 (18:01 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 1 Aug 2017 09:02:12 +0000 (18:02 +0900)
Change-Id: I35f70eedb4845cd8645bff4dceeabde93ae2b5ea
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
13 files changed:
CMakeLists.txt
packaging/context-job-scheduler.spec
src/agent/AgentTypes.h [new file with mode: 0644]
src/agent/CMakeLists.txt [new file with mode: 0644]
src/agent/ContactsDbAgent.cpp [new file with mode: 0644]
src/agent/ContactsDbAgent.h [new file with mode: 0644]
src/agent/CreateAgent.cpp [new file with mode: 0644]
src/agent/GeofenceAgent.cpp [new file with mode: 0644]
src/agent/GeofenceAgent.h [new file with mode: 0644]
src/server/ContextPublisher.cpp
src/server/JobManager.cpp
src/server/MethodCallHandler.cpp
src/server/publisher/GeofenceEvent.cpp [new file with mode: 0644]

index 183093691cf7eb96189807fee846226efd2aec83..3a85b76228c7563da1c7e33096d7c42fd7869d77 100644 (file)
@@ -32,3 +32,4 @@ ADD_SUBDIRECTORY(src/client-dummy)
 ADD_SUBDIRECTORY(src/server-dummy)
 ADD_SUBDIRECTORY(src/client)
 ADD_SUBDIRECTORY(src/server)
+ADD_SUBDIRECTORY(src/agent)
index d1821d2f42bedf9473d662ae6ed451bc47efe790..09155d1fde54aecca458e2f0c35abf9ec21f3728 100644 (file)
@@ -95,6 +95,7 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall
 %manifest packaging/%{name}.manifest
 %{_libdir}/lib%{name}-client-genuine.so.*
 %{_libdir}/lib%{name}-server-genuine.so.*
+%{_libdir}/context-agent/*.so.*
 %license LICENSE
 
 
diff --git a/src/agent/AgentTypes.h b/src/agent/AgentTypes.h
new file mode 100644 (file)
index 0000000..9adcd0a
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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
diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1813788
--- /dev/null
@@ -0,0 +1,21 @@
+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)
diff --git a/src/agent/ContactsDbAgent.cpp b/src/agent/ContactsDbAgent.cpp
new file mode 100644 (file)
index 0000000..2cd247c
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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;
+}
diff --git a/src/agent/ContactsDbAgent.h b/src/agent/ContactsDbAgent.h
new file mode 100644 (file)
index 0000000..e3529d3
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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
diff --git a/src/agent/CreateAgent.cpp b/src/agent/CreateAgent.cpp
new file mode 100644 (file)
index 0000000..2614319
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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;
+}
diff --git a/src/agent/GeofenceAgent.cpp b/src/agent/GeofenceAgent.cpp
new file mode 100644 (file)
index 0000000..8e9c874
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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;
+}
diff --git a/src/agent/GeofenceAgent.h b/src/agent/GeofenceAgent.h
new file mode 100644 (file)
index 0000000..c11c921
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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
index 5adc1ef55ad45e00a516ee6586687049142a8de8..2fddfe45ee5b2666c9858cd3f3e941242b6182c2 100644 (file)
@@ -18,6 +18,7 @@
 #include <regex>
 #include <ContextTypes.h>
 #include <SharedUtil.h>
+#include <ServerUtil.h>
 #include "IContextObserver.h"
 #include "ContextPublisher.h"
 #include "publisher/CustomPublisher.h"
@@ -44,6 +45,7 @@ ContextPublisher* ContextPublisher::build(const char* uri, uid_t uid)
 
        // Custom publishers
        IF_FAIL_THROW(isCustomUri(uri), E_SUPPORT);
+       IF_FAIL_THROW(!util::is_system(uid), E_SUPPORT);
        return new CustomPublisher(uri, uid);
 }
 
index c1e9a604b7c91b8c8b9ac76c7838ecadd08a9aea..306b03df0ff93439072ac06a15b454c3a19db995 100644 (file)
@@ -321,9 +321,6 @@ JobInfo* JobManager::__getDuplicate(const std::string& ownerId, JobInfo* target)
 
 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);
index 7842a4e365cf7b87820a714b8016e57d6d398121..5b36222fea44784396dabd4ed0597cf8b10376ea 100644 (file)
@@ -276,6 +276,7 @@ void MethodCallHandler::__registerCustom(IMethodCall& methodCall)
        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());
 
@@ -289,6 +290,7 @@ void MethodCallHandler::__unregisterCustom(IMethodCall& methodCall)
        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());
 
@@ -303,6 +305,7 @@ void MethodCallHandler::__isRegisteredCustom(IMethodCall& methodCall)
        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);
 
diff --git a/src/server/publisher/GeofenceEvent.cpp b/src/server/publisher/GeofenceEvent.cpp
new file mode 100644 (file)
index 0000000..dcdceff
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * 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
+}