Add runner skeleton code
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 2 Feb 2021 07:37:05 +0000 (16:37 +0900)
committer최창규/Tizen Platform Lab(SR)/Engineer/삼성전자 <changyu.choi@samsung.com>
Thu, 4 Feb 2021 07:09:55 +0000 (16:09 +0900)
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/server/runner.cc [new file with mode: 0644]
src/server/runner.hh [new file with mode: 0644]
src/server/worker_thread.cc [new file with mode: 0644]
src/server/worker_thread.hh [new file with mode: 0644]

diff --git a/src/server/runner.cc b/src/server/runner.cc
new file mode 100644 (file)
index 0000000..c5d2687
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <string>
+
+#include "pkg_request.hh"
+#include "runner.hh"
+
+namespace pkgmgr_server {
+
+Runner::Runner(int thread_num) : thread_num_(thread_num) {
+  /* TODO implement code */
+}
+
+void Runner::OnReceiveRequest(pkgmgr_common::AbstractSocket socket) {
+  /* TODO implement code */
+}
+
+bool Runner::QueueRequest(pkgmgr_common::AbstractSocket socket) {
+  /* TODO implement code */
+  return true;
+}
+
+}  // namespace pkgmgr_server
diff --git a/src/server/runner.hh b/src/server/runner.hh
new file mode 100644 (file)
index 0000000..7921ed4
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 SERVER_RUNNER_HH_
+#define SERVER_RUNNER_HH_
+
+#include <memory>
+
+#include "../common/socket/abstract_socket.hh"
+#include "worker_thread.hh"
+
+namespace pkgmgr_server {
+
+class Runner {
+ public:
+  Runner(int thread_num);
+  ~Runner() = default;
+  void OnReceiveRequest(pkgmgr_common::AbstractSocket socket);
+  bool QueueRequest(pkgmgr_common::AbstractSocket socket);
+
+ private:
+  int thread_num_;
+  std::unique_ptr<WorkerThread> thread_pool_;
+};
+
+}  // namespace pkgmgr_server
+
+#endif  // SERVER_RUNNER_HH_
diff --git a/src/server/worker_thread.cc b/src/server/worker_thread.cc
new file mode 100644 (file)
index 0000000..f6c4740
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <mutex>
+#include <queue>
+#include <thread>
+
+#include "pkg_request.hh"
+#include "worker_thread.hh"
+
+namespace pkgmgr_server {
+
+WorkerThread::WorkerThread(int num) {
+  /* TODO implement code */
+}
+
+bool WorkerThread::PushQueue(PkgRequest req) {
+  /* TODO implement code */
+  return true;
+}
+
+void Run() {
+  /* TODO implement code */
+}
+
+PkgRequest PopQueue() {
+  /* TODO implement code */
+  int fd = 3;
+  return PkgRequest(fd);
+}
+
+}  // namespace pkgmgr_server
diff --git a/src/server/worker_thread.hh b/src/server/worker_thread.hh
new file mode 100644 (file)
index 0000000..4c0f750
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 SERVER_WORKER_THREAD_HH_
+#define SERVER_WORKER_THREAD_HH_
+
+#include <mutex>
+#include <queue>
+#include <thread>
+#include <vector>
+
+#include "pkg_request.hh"
+
+namespace pkgmgr_server {
+
+class WorkerThread {
+ public:
+  WorkerThread(int num);
+  ~WorkerThread() = default;
+  bool PushQueue(PkgRequest req);
+
+ private:
+  void Run();
+  PkgRequest PopQueue();
+
+ private:
+  std::queue<PkgRequest> queue_;
+  std::vector<std::thread> threads_;
+  std::mutex lock_;
+};
+
+}  // namespace pkgmgr_server
+
+#endif  // SERVER_WORKER_THREAD_HH_