cpp/features/feature.cpp \
cpp/features/feature_manager.cpp \
cpp/features/feature_manager_c.cpp \
- cpp/features/feature_wsp.cpp
+ cpp/features/feature_wsp.cpp \
+\
+ cpp/inst/AppInst.cpp \
+ cpp/inst/AppInstCont.cpp
OBJS_C := $(SRC_C:.c=.o)
OBJS_CPP := $(SRC_CPP:.cpp=.o)
return "0x" + ss.str();
}
+static inline bool str2pid(const char *str, pid_t &pid)
+{
+ char c;
+ std::stringstream ss(str);
+ ss >> pid;
+ if (ss.fail() || ss.get(c)) {
+ // not an integer
+ return false;
+ }
+ return true;
+}
+
+static inline bool buf2uint64(const char *buf, size_t len, uint64_t &out)
+{
+ if (len != 8)
+ return false;
+
+ out = 0;
+ for (int i = len - 1; i >= 0; --i) {
+ out <<= 8;
+ out += (uint8_t)buf[i];
+ }
+
+ return true;
+}
static inline ssize_t write_to_file(const char *filename,
const void *buf, size_t len)
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include "AppInst.h"
+#include "AppInstTizen.h"
+#include "AppInstRunning.h"
+#include "AppInstCommon.h"
+#include "AppInstWeb.h"
+#include "debug.h"
+
+
+AppInst *AppInst::create(AppType type, const AppInstInfo &info)
+{
+ AppInst *app(0);
+
+ switch (type) {
+ case AT_TIZEN:
+ app = new AppInstTizen();
+ break;
+ case AT_RUNNING:
+ app = new AppInstRunning();
+ break;
+ case AT_COMMON:
+ app = new AppInstCommon();
+ break;
+ case AT_WEB:
+ app = new AppInstWeb();
+ break;
+ default:
+ LOGE("'app type' incorrect, type=%d\n", type);
+ return 0;
+ }
+
+ if (app) {
+ int ret = app->init(info);
+ if (ret) {
+ LOGE("[%s] initialization error, ret=%d\n", type2str(type), ret);
+ delete app;
+ app = 0;
+ }
+ }
+
+ return app;
+}
+
+void AppInst::destroy(AppInst *app)
+{
+ app->uninit();
+ delete app;
+}
+
+int AppInst::init(const AppInstInfo &info)
+{
+ _info = new AppInstInfo(info);
+ if (_info == 0)
+ return -ENOMEM;
+
+ return doInit();
+}
+
+void AppInst::uninit()
+{
+ doUninit();
+ delete _info;
+ _info = 0;
+}
+
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#ifndef APPINST_H
+#define APPINST_H
+
+
+#include <string>
+#include <vector>
+
+
+typedef std::vector<char> ByteArray;
+
+
+#define APP_TYPE_LIST \
+ X(UNKNOWN) \
+ X(TIZEN) \
+ X(RUNNING) \
+ X(COMMON) \
+ X(WEB)
+
+
+#define X(type) AT_##type,
+enum AppType {
+ /* AT_xxx */
+ APP_TYPE_LIST
+};
+#undef X
+
+static inline const char *type2str(AppType type)
+{
+#define X(type) case AT_##type: return #type;
+ switch (type) {
+ APP_TYPE_LIST
+ }
+#undef X
+ return "error_type";
+}
+
+
+class AppInstInfo
+{
+public:
+ AppInstInfo(const std::string &id, const std::string &path,
+ const ByteArray &data) :
+ _id(id),
+ _path(path),
+ _data(data)
+ {}
+
+ const std::string &id() const { return _id; }
+ const std::string &path() const { return _path; }
+ const ByteArray &data() const { return _data; }
+
+private:
+ const std::string _id;
+ const std::string _path;
+ const ByteArray _data;
+};
+
+
+class AppInst
+{
+public:
+ static AppInst *create(AppType type, const AppInstInfo &info);
+ static void destroy(AppInst *app);
+
+ const AppInstInfo &info() const { return *_info; }
+
+protected:
+ AppInst() : _info(0) {}
+ virtual ~AppInst() {}
+
+private:
+ int init(const AppInstInfo &info);
+ void uninit();
+
+ int virtual doInit() { return 0; }
+ void virtual doUninit() {}
+
+ const AppInstInfo *_info;
+};
+
+
+#endif // APPINST_H
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#ifndef APPINSTCOMMON_H
+#define APPINSTCOMMON_H
+
+#include "AppInst.h"
+#include "common.h"
+#include "debug.h"
+
+
+class AppInstCommon : public AppInst
+{
+ int doInit()
+ {
+ if (info().id().size()) {
+ LOGE("[%s] error 'app ID' is not empty '%s'\n",
+ type2str(AT_COMMON), info().id().c_str());
+ return -EINVAL;
+ }
+
+ return 0;
+ }
+};
+
+
+#endif // APPINSTCOMMON_H
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include "AppInstCont.h"
+#include "AppInst.h"
+
+
+AppInstCont &AppInstCont::instance()
+{
+ static AppInstCont cont;
+
+ return cont;
+}
+
+AppInstCont::AppInstCont()
+{
+}
+
+AppInstCont::~AppInstCont()
+{
+ clear();
+}
+
+int AppInstCont::add(AppType type, const std::string &id,
+ const std::string &path, const ByteArray &data)
+{
+ AppInstInfo info(id, path, data);
+
+ AppInst *app = AppInst::create(type, info);
+ if (app == 0)
+ return -EINVAL;
+
+ _list.push_back(app);
+
+ return 0;
+}
+
+void AppInstCont::clear()
+{
+ for (AppInstList::const_iterator it = _list.begin(); it != _list.end(); ++it)
+ AppInst::destroy(*it);
+
+ _list.clear();
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#ifndef APPINSTCONT_H
+#define APPINSTCONT_H
+
+
+#include <list>
+#include "AppInst.h"
+
+
+class AppInstCont
+{
+public:
+ static AppInstCont &instance();
+
+ int add(AppType type, const std::string &id, const std::string &path, const ByteArray &data);
+ void clear();
+
+ template <typename T, typename Data>
+ void for_each(void (*func)(const T&, Data&), Data& data)
+ {
+ for (AppInstList::const_iterator it = _list.begin(); it != _list.end(); ++it) {
+ T *app = dynamic_cast<T*>(*it);
+ if (app)
+ func(*app, data);
+ }
+ }
+
+private:
+ AppInstCont();
+ ~AppInstCont();
+
+ typedef std::list<AppInst *> AppInstList;
+
+ AppInstList _list;
+};
+
+
+#endif // APPINSTCONT_H
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#ifndef APPINSTRUNNING_H
+#define APPINSTRUNNING_H
+
+
+#include "AppInst.h"
+#include "common.h"
+#include "debug.h"
+
+
+class AppInstRunning : public AppInst
+{
+public:
+ pid_t pid() { return _pid; }
+
+private:
+ int doInit()
+ {
+ if (!str2pid(info().id().c_str(), _pid)) {
+ LOGE("[%s] error convert 'app ID to pid'\n", type2str(AT_RUNNING));
+ return -EINVAL;
+ }
+
+ return 0;
+ }
+
+ pid_t _pid;
+};
+
+#endif // APPINSTRUNNING_H
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#ifndef APPINSTTIZEN_H
+#define APPINSTTIZEN_H
+
+
+#include "AppInst.h"
+#include "common.h"
+#include "debug.h"
+
+
+class AppInstTizen : public AppInst
+{
+public:
+ uint64_t mainOffset() const { return _mainOffset; }
+
+private:
+ int doInit()
+ {
+ const ByteArray &data = info().data();
+
+ if (!buf2uint64(data.data(), data.size(), _mainOffset)) {
+ LOGE("[%s] error convert 'setup data'\n", type2str(AT_TIZEN));
+ return -EINVAL;
+ }
+
+ return 0;
+ }
+
+ uint64_t _mainOffset;
+};
+
+
+#endif // APPINSTTIZEN_H
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2015
+ *
+ * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#ifndef APPINSTWEB_H
+#define APPINSTWEB_H
+
+
+#include "AppInst.h"
+#include "debug.h"
+
+
+class AppInstWeb : public AppInst
+{
+ int doInit()
+ {
+ if (info().id().empty()) {
+ LOGE("[%s] error 'app ID' is empty\n", type2str(AT_WEB));
+ return -EINVAL;
+ }
+
+ return 0;
+ }
+};
+
+
+#endif // APPINSTWEB_H
#define IS_OPT_SET_IN(OPT, reg) (reg & (OPT))
#define IS_OPT_SET(OPT) IS_OPT_SET_IN((OPT), prof_session.conf.use_features0)
-enum app_type {
- AT_TIZEN =0x01,
- AT_LAUNCHED =0x02,
- AT_COMMON =0x03
-};
enum supported_device {
DEVICE_FLASH,
DEVICE_CPU,