summaryrefslogtreecommitdiffstats
path: root/src/hs-appinfo.h
blob: 3355686ca6b3a95f28041c151a16d18793962f21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .
/*
 * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
 *
 * 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 HOMESCREEN_APPINFO_H
#define HOMESCREEN_APPINFO_H

#include <string>
#include <mutex>
#include <memory>
#include <vector>
#include <functional>
#include <unordered_map>
#include "hs-helper.h"
#include "hs-proxy.h"


struct AppDetail {
    std::string name;
    std::string id;
    std::string detail; // detail json_object string
    bool periphery;

    std::string getProperty(std::string key) const;
};

class HS_AppInfo {
public:
    HS_AppInfo() = default;
    ~HS_AppInfo();
    HS_AppInfo(HS_AppInfo const &) = delete;
    HS_AppInfo &operator=(HS_AppInfo const &) = delete;
    HS_AppInfo(HS_AppInfo &&) = delete;
    HS_AppInfo &operator=(HS_AppInfo &&) = delete;

    static HS_AppInfo* instance(void);
    int init(afb_api_t api);
    int onEvent(afb_api_t api, const char *event, struct json_object *object);

    void getRunnables(struct json_object **object);
    std::string getAppProperty(const std::string appid, std::string key) const;
    std::string checkAppId(const std::string &appid);

private:
    int updateAppDetailList(afb_api_t api, struct json_object *object);
    void createAppDetailList(struct json_object *object);
    std::string parseAppDetail(struct json_object *object, AppDetail &info) const;
    void addAppDetail(struct json_object *object);
    void removeAppDetail(std::string appid);
    struct json_object* retrieveRunnables(struct json_object *obj_runnables, std::string id);
    void pushAppListChangedEvent(const char *oper, struct json_object *object);
    std::string id2appid(const std::string &id) const;
    bool isPeripheryApp(const char *appid) const;

    // applications can't display on launcher
    const std::vector<const char*> periphery_app_list {
        "launcher",
        "homescreen",
        "onscreenapp",
        "restriction"
    };

    typedef int (HS_AppInfo::*func_handler)(afb_api_t, struct json_object*);
    static const std::unordered_map<std::string, func_handler> concerned_event_list;

private:
    static HS_AppInfo* me;
    HS_AfmMainProxy* afmmain = nullptr;
    std::unordered_map<std::string, std::string> appid2name;
    std::unordered_map<std::string, std::string> name2appid;
    std::unordered_map<std::string, AppDetail> app_detail_list;
    std::mutex mtx;
};

#endif // HOMESCREEN_APPINFO_H