• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright JS Foundation and other contributors, http://js.foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef _JERRYSCRIPT_MBED_LIBRARY_REGISTRY_REGISTRY_H
16 #define _JERRYSCRIPT_MBED_LIBRARY_REGISTRY_REGISTRY_H
17 
18 #include <vector>
19 #include "stdint.h"
20 
21 #define JERRY_USE_MBED_LIBRARY(NAME) \
22     mbed::js::LibraryRegistry::getInstance().add(jsmbed_wrap_registry_entry__ ## NAME)
23 
24 namespace mbed {
25 namespace js {
26 
27 typedef void (*library_registration_function_t)(void);
28 
29 class LibraryRegistry {
30  private:
31     static LibraryRegistry instance;
32 
33  public:
getInstance()34     static LibraryRegistry& getInstance() {
35         return instance;
36     }
37 
add(library_registration_function_t lib_func)38     void add(library_registration_function_t lib_func) {
39         funcs.push_back(lib_func);
40     }
41 
register_all()42     void register_all() {
43         for (std::size_t i = 0; i < funcs.size(); i++) {
44             funcs[i]();
45         }
46     }
47 
48  private:
LibraryRegistry()49     LibraryRegistry() {}
50 
51     std::vector<library_registration_function_t> funcs;
52 };
53 
54 }  // namespace js
55 }  // namespace mbed
56 
57 #endif  // _JERRYSCRIPT_MBED_LIBRARY_REGISTRY_REGISTRY_H
58