Commit 1b778229 authored by clotee's avatar clotee

Initail commit

parents
Pipeline #6678 failed with stages
{
"presets": [
["env", {
"targets": {
"modules": false,
"loose": true,
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-0"
],
"plugins": [
["import",[{
"libraryName": "weex-ui",
"libraryDirectory": "packages",
"style": false
}, {
"libraryName": "bui-weex",
"libraryDirectory": "src/components",
"style": false
}]],
["transform-runtime", {
"polyfill": false,
"helpers": false
}]
],
"env": {
"test": {
"presets": ["env", "stage-0"],
"plugins": ["istanbul"]
}
}
}
[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[{.eslintrc,.babelrc,.stylelintrc,jest.config,*.json,*.jsb3,*.jsb2,*.bowerrc}]
indent_style=space
indent_size=2
[*.scss]
indent_style=space
indent_size=2
[{.analysis_options,*.yml,*.yaml}]
indent_style=space
indent_size=2
{
"env": {
"es6": true,
"node": true,
"mocha": true,
"browser": true
},
"plugins": [
"html"
],
"parserOptions": {
"sourceType": "module"
},
"globals": {
"weex": true,
"Vue": true
},
"rules": {
"semi": "off",
"indent": 0,
"quotes": [ "error", "single" ],
"no-control-regex": 0,
"no-extend-native": 0,
"handle-callback-err": 0,
"camelcase": 0,
"no-return-assign": [ 2, "except-parens" ]
},
"extends": [
"vue"
],
"parser": "babel-eslint"
}
Created by IDE
.DS_Store
.idea/
*.iml
docs
.*
!.gitignore
!.eslintrc
!.editorconfig
!.babelrc
# Node
eros-widget/
logs
*.log
npm-debug.log*
.npm
node_modules
dist
bower_components
# Runtime data
pids
*.pid
*.seed
# Android
# built application files
*.apk
*.ap_
wxframework
sdk
ErosPluginAmap
erosplugingt
erospluginumeng
erospluginwxpay
nexus
erospluginum
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
sign.properties
# Eclipse project files
.classpath
.project
# Android Studio
.idea/
.gradle
/*/local.properties
/*/outd
build/
.idea/
.gradle/
android/playground/local.properties
/*/*/production
*.iml
*.iws
*.ipr
*~
*.swp
# END Android
# IOS
# Xcode
*/build/*
*.pbxuser
*.pbxprog
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
WeexiOSSDK
Benmu-iOS-Library
#CocoaPods
Pods
*.xccheckout
*.xcworkspacedata
*.xcworkspace
Podfile.lock
# END IOS
MIT License
Copyright (c) 2018 本木医疗大前端
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
## 介绍
> lm-weex app 快速开发模板,可通过脚手架 lm-weex-cli `init` 指令快速生成。
### 运行命令:```lm-weex dev```
### 项目构建:```lm-weex build```
### 打包到IOS:```lm-weex pack ios```
### 打包到安卓:```lm-weex pack android```
// appBoard,mediator 不建议进行修改 如果修改了 也请对应修改
module.exports = {
'eslint': false,
'webpackWarnings': false,
'exports': [
// appBoard
'js/config/index.js',
// mediator
'js/mediator/index.vue',
// home
'js/pages/index.vue',
'js/pages/contact/index.vue',
'js/pages/user/index.vue',
'js/pages/user/create.vue',
],
'alias': {
'Components': 'js/components',
'Common': 'js/common',
'Config': 'js/config',
'Widget': 'js/widget',
'Pages': 'js/pages',
'Provider': 'js/provider',
'Utils': 'js/utils'
},
'diff': {
'pwd': '/Users/yangmingzhe/Work/opensource/eros-diff-folder',
'proxy': 'https://app.weex-eros.com/source'
},
'server': {
'path': './',
'port': 8889
},
'mockServer': {
'port': 52077,
'mockDir': './dist/mock'
},
'socketServer': {
'port': 8890,
'switch': true
}
}
module.exports = {
'appName': 'weex-template',
'appBoard': '/config/index.js',
// android 监听全局事件homeBack 如果为true 安卓端需要自行调用router.finish方法来关闭应用
'androidIsListenHomeBack': 'true',
'version': {
'android': '1.0.0',
'iOS': '1.0.0'
},
'page': {
'homePage': 'tabBar',
'mediatorPage': '/mediator/index.js',
'navBarColor': '#1A887D',
'navItemColor': '#ffffff'
},
'url': {
'image': 'http://www.superlinksoft.com/img-company/XXX',
'bundleUpdate': 'http://localhosts:3001/app/check'
},
'zipFolder': {
'iOS': '/ios/LMWeex/LMWeex',
'android': '/android/LMWeex/app/src/main/assets'
},
'getui': {
'enabled': 'false',
'appId': '',
'appKey': '',
'appSecret': ''
},
'tabBar': {
'color': '#FFFFFF',
'selectedColor': '#ededed',
'backgroundColor': '#1A887D',
'borderColor': '#1A887D',
'list': [{
'pagePath': '/pages/index.js',
'text': '首页',
'icon': 'bmlocal://assets/TabBar_Item1@2x.png',
'selectedIcon': 'bmlocal://assets/TabBar_Item1_Selected@2x.png',
'navShow': 'true',
'navTitle': "首页"
},
{
'pagePath': '/pages/contact/index.js',
'text': '我的任务',
'icon': 'bmlocal://assets/TabBar_Item2@2x.png',
'selectedIcon': 'bmlocal://assets/TabBar_Item2_Selected@2x.png',
'navShow': 'true',
'navTitle': '任务'
},
{
'pagePath': '/pages/user/index.js',
'text': '个人中心',
'icon': 'bmlocal://assets/TabBar_Item3@2x.png',
'selectedIcon': 'bmlocal://assets/TabBar_Item3_Selected@2x.png',
'navShow': 'true',
'navTitle': '我'
}
]
}
}
10.0.7.234
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "lm-template-source",
"version": "1.0.0",
"description": "a project for weex",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"weex"
],
"author": "clotee",
"license": "MIT",
"dependencies": {
"bui-weex": "^0.4.17",
"eros-widget": "^1.0.2-beta.2",
"weex-ui": "^0.6.0beta-2"
},
"devDependencies": {
"babel-core": "6.26.0",
"babel-eslint": "^8.2.2",
"babel-plugin-import": "^1.11.0",
"babel-plugin-transform-runtime": "~6.23.0",
"babel-preset-env": "~1.5.2",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.22.0",
"bindingx-parser": "0.0.x",
"eslint": "^4.17.0",
"eslint-plugin-html": "^4.0.2",
"eslint-plugin-vue": "^4.3.0"
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// classpath 'com.benmu.eros:eros-raven:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
allprojects {
repositories {
jcenter()
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
repositories {
google()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
}
apply plugin: 'com.android.application'
//apply plugin: 'eros-revan'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
flavorDimensions 'default'
defaultConfig {
applicationId APPLICATION_ID
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
ndk {
abiFilters "x86"
abiFilters "armeabi"
}
}
signingConfigs {
eros {
keyAlias 'LMWeexDemo'
keyPassword 'gsst2019'
storeFile file('../com.gsst.lm.keystore')
storePassword 'gsst2019'
v2SigningEnabled false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.eros
manifestPlaceholders=[
GETUI_APP_ID:GETUI_APPID,
GETUI_APP_KEY:GETUI_APPKEY,
GETUI_APP_SECRET:GETTUI_APPSECRET,
APP_ID:APPLICATION_ID
]
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.eros
manifestPlaceholders=[
GETUI_APP_ID:GETUI_APPID,
GETUI_APP_KEY:GETUI_APPKEY,
GETUI_APP_SECRET:GETTUI_APPSECRET,
APP_ID:APPLICATION_ID
]
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
productFlavors {
samplechannel{
dimension 'default'
}
yingyongbao{
dimension 'default'
}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
sourceSets {
main {
jniLibs.srcDirs=['../wxframework/libs']
}
}
}
repositories {
mavenCentral()
flatDir {
dirs '../wxframework/libs', 'libs'
}
google()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:support-v4:${PROJECT_SUPPORTLIBVERSION}"
testCompile 'junit:junit:4.12'
//基础库
compile project(':nexus')
compile project(':wxframework')
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/Carry/Documents/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-samplechannel-release.apk","properties":{"packageId":"com.benmu.wx","split":"","minSdkVersion":"14"}}]
\ No newline at end of file
package com.benmu.wx;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.benmu.wxframework", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.gsst.lm">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
<!-- 这个权限用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 这个权限用于访问GPS定位 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="getui.permission.GetuiService.com.bmdoctor.jyt"/>
<!--amap额外权限-->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name="com.gsst.lm.App"
android:theme="@style/AppTheme.NoActionBar"
>
<activity android:name="com.eros.framework.activity.MainActivity" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="${APP_ID}.categoty.page"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
</activity>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="screenOrientation"
/>
<!--图片预览Activity-->
<activity
android:name="com.eros.framework.activity.BrowseImgActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Light.NoTitleBar"/>
<activity
android:name="com.gsst.lm.activity.SplashActivity"
android:theme="@style/WelcomeStyle"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.eros.framework.activity.GlobalWebViewActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="${APP_ID}.category.web"/>
</intent-filter>
</activity>
<activity android:name="com.eros.framework.activity.DebugActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="${APP_ID}.category.debug"/>
</intent-filter>
</activity>
<!--wxApi-->
<activity
android:name=".wxapi.WXEntryActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="your wx appId"/>
</intent-filter>
</activity>
<activity
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
android:launchMode="singleTop"/>
<!--amap-->
<service android:name="com.amap.api.location.APSService"></service>
<!--amap finish-->
<meta-data
android:name="PUSH_APPID"
android:value="${GETUI_APP_ID}"/>
<meta-data
android:name="PUSH_APPKEY"
android:value="${GETUI_APP_KEY}"/>
<meta-data
android:name="PUSH_APPSECRET"
android:value="${GETUI_APP_SECRET}"/>
<receiver
android:name="com.gsst.erosplugingt.GTPushReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.igexin.sdk.action.${GETUI_APP_ID}"/>
</intent-filter>
</receiver>
</application>
</manifest>
{"filesMd5":[{"page":"/config/index.js","md5":"8814afcdca615ab40b7d10698e74f021"},{"page":"/mediator/index.js","md5":"fa33c2ae36b1f611a3b1a6bf095e2e2f"},{"page":"/pages/contact/index.js","md5":"8ba1cdbaabce8994ca7e5beadc42e5e9"},{"page":"/pages/index.js","md5":"f44fe5ccd836824b4cff8534ada35894"},{"page":"/pages/user/index.js","md5":"4594a2d69a6dc423ac6e15b6de4e14e4"},{"page":"/iconfont/font_1469606063_76593.ttf","md5":"f6222bcfedff4a817bb50df7a049d1db"},{"page":"/iconfont/font_1469606522_9417143.woff","md5":"6cf5490fd14ff83350ff952bb5b8e484"},{"page":"/iconfont/font_zn5b3jswpofuhaor.ttf","md5":"c0356b22e8235d2b0be8880cc81894cc"},{"page":"/iconfont/iconfont-eros.ttf","md5":"68780fad0047dc5b02cb613ebb08cda1"},{"page":"/iconfont/iconfont.ttf","md5":"ec86bfe5bdb872bad2b2af4f11da14f4"},{"page":"/assets/TabBar_Item1@2x.png","md5":"2ddd5ec0afdf265345caf505301f2efc"},{"page":"/assets/TabBar_Item1_Selected@2x.png","md5":"a37d972349b892b7f876711b3971c0cd"},{"page":"/assets/TabBar_Item2@2x.png","md5":"1229e0510406a1a7d6bd00971ad05f29"},{"page":"/assets/TabBar_Item2_Selected@2x.png","md5":"db7ed62ffffc1550c8195bf1f7da5e36"},{"page":"/assets/TabBar_Item3@2x.png","md5":"6365961c3362d4bac80d85dd5d066f12"},{"page":"/assets/TabBar_Item3_Selected@2x.png","md5":"7b6f120bed320f418f37bce139bc39a0"}],"android":"1.0.0","iOS":"1.0.0","appName":"weex-template","jsVersion":"53d116552f21bcbcd787370329470ff7","timestamp":1552417626832,"jsPath":"https://app.weex-eros.com/source"}
"f9NU7t0+Vw7b8RQQF2GtwNXKRjyfuTmlgQjeVKRAxlvTj1WDYhE6weQsoAQSgNfaOkGIPm+2AJl4POCXarpYDZES71SyF6jdpT2BU88wbSk/ZIWARUSrQ3nMS0OZyoMinT/OWmuOGQt2WTlkgyXfemywHZQacCh5UzR8uxqkBWookoR4azSbtJmv7MC4ss+Lj99G7kjXnmZ7yV8VGfcesODf+A30CrTkMtpLr9TddNHVeXuocJnaS3tvMV+Ufuhc7WmL50FbH4d8pKBPpTyPa79NSieiP4vdi4TErj+I6Ofw4xWhcn8Kh+pPWTsqhXuaSQOd6DVfKStre/QLCCNEC7c+A1pairel+tKnQVOvZu2GLqCxOOQc/Xrhbit6BLHoKsqWVMu3lnkiP0SNLi1I16LfS/WpQlFLg+Xdk8UD0Sg/FDfPqLOXWqcUoJh/OG2xJwDvYNfv1N+9MZOQQfrHjyeW8Ege8vhElqpZCuKg0kkoG1WyoP0NHHJaq64tw5EEfB3enZR6hCNM5AtsBjy9LxYpB9iLlQoDfj7sKIQ/mpozjth2mzrZgtPsyaDSI3Hs08vZ6UEW4xmf9jTOqI8Fz6y5dltkK5UUOkZ2Q50Xr3KORxYWyxYu0FiR8y2x4WX1kVxcnP6AUYM7vkh37OmTDF9kmQQwPqDgJO/foWJZpImUcJ6YolNS7X9q84hkdJOWVR1AG4yxjrTjyttTXvbMKiZtxgNXXNerpZ2gCu1ZiJbul2fLg5VqSrkJadn6Yasc5N0/dslYsZUtzVEmcZHOtN83F/2HnomSZ+93155h9vqfpk3re4MP/RGCWBM+0nA1XHSso2quapSwBXFeSbkeoTwbreGrbAjzpUiCwoBRg76V2RjAmazAr2ivmuRMphcTmixjFLZktuGsjnb+kHGq9zNV+uHsuMLA1Zvg/GRfRjPVJJhCdDkvpF3fbck6wvNS0XZtBoxLP+SunqYFnYaWpb1neDaYu2FGUb6CDXGkjKskIKw8LNr96p5JcfcrTPR7KNdp8FJzQM1dkQyYOory/I3u/LYtNsUjgBqk67VvmIIbGXF8ENKeBOkRUfqv06xBCGzCOoang7W3DnOlUi3DNjovggXoYagCyvpd0wMkwDkpcaYFJQgw2gNH+RfNgeUNAZt3U5SVAsllMM/wXb4qP3FMCujvqT/1m2N+soeOQzvJ7D0yMGfj7hJwGFlZxrb2A6d3qwL2AQiSPJKmRS/9ZEBylaExb4mz0xmG+D2HiUNqGF6A9rwOsZmUZPgkbdeIcgS0/h6/dieXXkWdJJsJBgz56aC3Az/GQhzXVX/GrAzSEDeSx1kkoPCuI4yqEdls+ucgotAF3NlkHM6XnrMr6oo/rdtqfADQepDYYC949C5y4Htx10FYRcpkblH4LtD1naTYNl517oR5BYfGoGblzDMr8dRNgioDdckUJvHXIrLpp6NpONuU6nVLVjMINBaVMWqWB22wosbvusOzk8FMVSvaeX4KtMnZMrv4UkyIC8oIJHNJvqAm8uAugNEu+c1dSiWDedylkEsizj9nFvWjXB6HoXLi3HELraDXejcLlrV1Jwvj1ykvbqeiVnLQcR60iOtzBre1ZTp6+35yfFFdMZvshMcnbnWfEnbUGp7YUym54DLczXYMvqJHY7RIv70OzdhzzgYCIlNDNMj1pktHx3y96v1kNrp5Cgi6Ha3rbI0OxJCeaVAgeBJouHkCuferr7LH3AgYri8IRmF86z3vzVQhOMxG8gDVR92hxdD/aT4="
package com.gsst.lm;
import android.app.Application;
import com.eros.framework.BMWXApplication;
/**
* Created by Carry on 2017/8/23.
*/
public class App extends BMWXApplication {
public Application mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
}
package com.gsst.lm.activity;
import android.app.Activity;
import android.os.Bundle;
import com.eros.framework.proxy.SplashActivityProxy;
import com.gsst.lm.R;
/**
* Created by Carry on 2017/8/23.
*/
public class SplashActivity extends Activity {
private SplashActivityProxy activityProxy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
activityProxy = new SplashActivityProxy();
activityProxy.onCreateInit(this);
}
@Override
protected void onStart() {
super.onStart();
activityProxy.onStart(this);
}
@Override
protected void onResume() {
super.onResume();
activityProxy.onResume(this);
}
@Override
protected void onRestart() {
super.onRestart();
activityProxy.onRestart(this);
}
@Override
protected void onPause() {
super.onPause();
activityProxy.onPause(this);
}
@Override
protected void onStop() {
super.onStop();
activityProxy.onStop(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
activityProxy.onDestroy(this);
}
}
//package com.eros.wx.wxapi;
//
//import android.os.Bundle;
//
//import com.eros.erospluginumeng.model.WXApiModule;
//import com.eros.framework.manager.ManagerFactory;
//import com.eros.framework.manager.impl.dispatcher.DispatchEventManager;
//import com.tencent.mm.opensdk.modelbase.BaseReq;
//import com.tencent.mm.opensdk.modelbase.BaseResp;
//import com.tencent.mm.opensdk.modelmsg.SendAuth;
//import com.tencent.mm.opensdk.openapi.IWXAPI;
//import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
//import com.umeng.socialize.weixin.view.WXCallbackActivity;
//
///**
// * Created by Dong Fuhai on 2014-07-22 16:42.
// *
// * @modify:
// */
//public class WXEntryActivity extends WXCallbackActivity implements IWXAPIEventHandler {
//
//
// public static WXEntryActivity activity;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// activity = this;
// //注册API
// IWXAPI mWXApi = WXApiModule.getInstans().getWXApi();
// if (mWXApi == null) return;
// mWXApi.handleIntent(getIntent(), this);
// }
//
//
// @Override
// public void onReq(BaseReq baseReq) {
//
// }
//
// @Override
// public void onResp(BaseResp baseResp) {
// if (baseResp instanceof SendAuth.Resp) {
// SendAuth.Resp newResp = (SendAuth.Resp) baseResp;
// ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(newResp);
// }
// this.finish();
// }
//}
//package com.eros.wx.wxapi;
//
//
//import android.app.Activity;
//import android.content.Intent;
//import android.os.Bundle;
//
//import com.eros.erospluginwxpay.WXApiModule;
//import com.eros.erospluginwxpay.model.WeChatPayResultModel;
//import com.eros.framework.manager.ManagerFactory;
//import com.eros.framework.manager.impl.dispatcher.DispatchEventManager;
//import com.tencent.mm.opensdk.constants.ConstantsAPI;
//import com.tencent.mm.opensdk.modelbase.BaseReq;
//import com.tencent.mm.opensdk.modelbase.BaseResp;
//import com.tencent.mm.opensdk.openapi.IWXAPI;
//import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
//
//public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
//
// private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
//
// private IWXAPI api;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// api = WXApiModule.getInstans().getWXApi();
// if (api != null) {
// api.registerApp(WXApiModule.getInstans().getAppId());
// api.handleIntent(getIntent(), this);
// }
// }
//
// @Override
// protected void onNewIntent(Intent intent) {
// super.onNewIntent(intent);
// setIntent(intent);
// if (api != null) {
// api.handleIntent(intent, this);
// }
// }
//
// @Override
// public void onReq(BaseReq req) {
//
// }
//
// /**
// * int ERR_OK = 0; int ERR_COMM = -1; int ERR_USER_CANCEL = -2; int ERR_SENT_FAILED = -3; int
// * ERR_AUTH_DENIED = -4; int ERR_UNSUPPORT = -5;
// */
// @Override
// public void onResp(BaseResp resp) {
// if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
// WeChatPayResultModel bean = new WeChatPayResultModel();
// bean.msg = resp.errStr;
// bean.resCode = resp.errCode;
// bean.status = resp.errCode;
// ManagerFactory.getManagerService(DispatchEventManager.class).getBus().post(bean);
// finish();
// }
// }
//}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
/>
</RelativeLayout>
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
<resources>
<string name="app_name">LMWeex</string>
<string name="umeng_socialize_female"></string>
<string name="umeng_socialize_male"></string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="WelcomeStyle" parent="FullscreenTheme">
<item name="android:windowBackground">@drawable/ic_splash</item>
</style>
</resources>
package com.benmu.wx;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// classpath 'com.benmu.eros:eros-raven:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
allprojects {
repositories {
jcenter()
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
repositories {
google()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
}
org.gradle.jvmargs=-Xmx1536m
android.enableAapt2=false
APPLICATION_ID=com.gsst.lm
GRADLE_TOOL_VERSION=3.0.0
GRADLE_VERSION=https\://services.gradle.org/distributions/gradle-4.1-all.zip
MIN_SDK_VERSION=14
TARGET_SDK_VERSION=25
COMPILE_SDK_VERSION=25
BUILD_TOOLS_VERSION=26.0.2
PROJECT_SUPPORTLIBVERSION=25.3.1
#start
GETUI_APPID=
GETUI_APPKEY=
GETTUI_APPSECRET=
#end
#Tue Nov 21 18:48:24 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
#!/usr/bin/env bash
echo "开始更新依赖库"
rm -rf wxframework/
rm -rf sdk/
rm -rf nexus/
rm -rf ErosPluginAmap/
rm -rf erosplugingt/
rm -rf erospluginwxpay/
rm -rf erospluginumeng/
git clone https://github.com/bmfe/WeexErosFramework.git "wxframework"
git clone https://github.com/bmfe/eros-nexus.git "nexus"
cd ../
echo "依赖库更新完成"
include ':app',':sdk',':nexus', ':wxframework'
// 基础库
project(':wxframework').projectDir = new File(settingsDir,'/wxframework/eros-framework')
project(':sdk').projectDir = new File(settingsDir,'/nexus/sdk')
project(':nexus').projectDir = new File(settingsDir,'/nexus/nexus')
#!/bin/bash
eros_prefix="[\033[34meros\033[0m]"
function error_exit {
echo "--------------------------------------------"
echo -e "\033[31m Error code is $1 \033[0m" 1>&2
echo ""
echo " Code tips: "
echo -e "\033[33m1 -> platforms/android/WeexFrameworkWrapper/ is not existed. \033[0m"
echo -e "\033[33m2 -> cannot cannot git pull platforms/android/WeexFrameworkWrapper/wxframework, you can try a manual operation. \033[0m"
echo -e "\033[33m3 -> cannot cannot git pull platforms/android/WeexFrameworkWrapper/sdk, you can try a manual operation. \033[0m"
echo -e "\033[33m4 -> cannot cannot git pull platforms/android/WeexFrameworkWrapper/nexus, you can try a manual operation. \033[0m"
echo -e "\033[33m5 -> cannot cannot git pull platforms/android/WeexFrameworkWrapper/ErosPluginAmap, you can try a manual operation. \033[0m"
echo -e "\033[33m6 -> cannot cannot git pull platforms/android/WeexFrameworkWrapper/erosplugingt, you can try a manual operation. \033[0m"
echo -e "\033[33m7 -> cannot cannot git pull platforms/android/WeexFrameworkWrapper/erospluginwxpay, you can try a manual operation. \033[0m"
echo -e "\033[33m8 -> cannot cannot git pull platforms/android/WeexFrameworkWrapper/erospluginumeng, you can try a manual operation. \033[0m"
exit 1
}
pwd || \
error_exit 1
echo -e "$eros_prefix Enter android project"
if [ -e wxframework/ ] || [ -e sdk/ ] || [ -e nexus/ ] || [ -e ErosPluginAmap/ ]
then
echo -e "$eros_prefix Start to updating."
cd wxframework/ && git pull || error_exit 2
# cd ../sdk/ && git pull || error_exit 3
cd ../nexus/ && git pull || error_exit 4
cd ../ErosPluginAmap/ && git pull || error_exit 5
cd ../erosplugingt/ && git pull || error_exit 6
cd ../erospluginwxpay/ && git pull || error_exit 7
cd ../erospluginumeng/ && git pull || error_exit 8
cd ..
echo -e "$eros_prefix \033[32mAndroid sdk has been updated, enjoy it! \033[0m"
else
echo -e "$eros_prefix No wxframework, sdk or bmwidget file, make sure you had been run eros install."
fi
\ No newline at end of file
*.pyc
build32/
build64/
cmake-build-debug
cscope.out
cmake_minimum_required(VERSION 3.4.1)
project(WeexCore)
add_subdirectory(Source)
cmake_minimum_required(VERSION 3.4.1)
set(WEEXCORE_LIBRARY_NAME weexcore)
message("${ANDROID_STL} ")
if ("${ANDROID_STL}" STREQUAL "c++_static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
elseif ("${ANDROID_STL}" STREQUAL "gnustl_static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y")
endif ()
add_compile_options(-fexceptions)
add_definitions(-DGNU_SUPPORT=1)
add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT=1)
add_definitions(-DDEBUG=1)
add_definitions(-DOS_ANDROID=1)
add_definitions(-DRENDER_LOG=0)
add_definitions(-DPERFORMANCE_LOG=0)
add_definitions(-DLAYOUT_LOG=0)
add_definitions(-DJSAPI_LOG=0)
add_definitions(-DDOM_PARSER_LOG=0)
set(COMMON_SRCS
./base/time_point.cc
./base/thread/thread_impl_posix.cc
./base/thread/thread_impl_android.cc
./base/message_loop/message_loop.cc
./base/message_loop/message_pump_posix.cc
./base/message_loop/message_pump_android.cc
./base/third_party/icu/icu_utf.cpp
./core/render/manager/render_manager.cpp
./core/render/page/render_page.cpp
./core/render/node/render_object.cpp
./core/render/node/factory/render_creator.cpp
./core/render/node/render_appbar.cpp
./core/render/node/render_list.cpp
./core/render/node/render_mask.cpp
./core/render/node/render_scroller.cpp
./core/render/node/render_text.cpp
./core/render/action/render_action_add_event.cpp
./core/render/action/render_action_remove_event.cpp
./core/render/action/render_action_add_element.cpp
./core/render/action/render_action_remove_element.cpp
./core/render/action/render_action_move_element.cpp
./core/render/action/render_action_createbody.cpp
./core/render/action/render_action_createfinish.cpp
./core/render/action/render_action_appendtree_createfinish.cpp
./core/render/action/render_action_layout.cpp
./core/render/action/render_action_update_attr.cpp
./core/render/action/render_action_update_style.cpp
./core/render/action/render_action_render_success.cpp
./core/render/action/render_action_trigger_vsync.cpp
./core/layout/layout.cpp
./core/layout/style.cpp
./core/css/css_value_getter.cpp
./core/config/core_environment.cpp
./core/moniter/render_performance.cpp
./core/bridge/platform/core_side_in_platform.cpp
./core/bridge/script/core_side_in_script.cpp
./core/parser/dom_wson.cpp
./core/data_render/ast.cc
./core/data_render/ast_builder.cc
./core/data_render/ast_factory.cc
./core/data_render/class.cc
./core/data_render/class_array.cc
./core/data_render/class_json.cc
./core/data_render/class_string.cc
./core/data_render/class_factory.cc
./core/data_render/class_object.cc
./core/data_render/code_generator.cc
./core/data_render/exec_state.cc
./core/data_render/object.cc
./core/data_render/parser.cc
./core/data_render/rax_jsx_ast.cc
./core/data_render/js_common_function.cc
./core/data_render/rax_parser.cc
./core/data_render/rax_parser_builder.cc
./core/data_render/rax_parser_context.cc
./core/data_render/rax_parser_scope.cc
./core/data_render/rax_parser_statistics.cc
./core/data_render/rax_source_locator.cc
./core/data_render/statement.cc
./core/data_render/string_table.cc
./core/data_render/table.cc
./core/data_render/token.cc
./core/data_render/tokenizer.cc
./core/data_render/vm.cc
./core/data_render/binary_file.cc
./core/data_render/vnode/vnode.cc
./core/data_render/vnode/vcomponent.cc
./core/data_render/vnode/vnode_exec_env.cc
./core/data_render/vnode/vnode_render_manager.cc
./core/data_render/vnode/vnode_render_context.cc
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/wson)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wson)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/json11)
SET(FINAL_ADD_LIBRARY
${COMMON_SRCS}
)
SET(FINAL_TARGET_LINK_LIBRARIES wson json11)
if (ANDROID)
## add_subdirectory for subdirectory has a CMakeLists.txt
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/IPC)
## include_directories for include head file
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/IPC)
set (ANDROID_SRCS
./android/jniprebuild/jni_load.cc
./android/base/jni/android_jni.cpp
./android/base/jni/jbytearray_ref.cpp
./android/base/jni/scoped_java_ref.cpp
./android/base/base64/base64.cpp
./android/base/base64/modp_base64/modp_b64.cc
./android/base/string/scoped_jstring.cpp
./android/base/string/scoped_jstring_utf8.cpp
./android/base/string/jstring_cache.cpp
./android/wrap/content_box_measurement_impl_android.cpp
./android/wrap/wx_debug_js_bridge.cpp
./android/wrap/native_render_object_utils_impl_android.cpp
./android/bridge/platform/android_side.cpp
./android/bridge/platform/android_bridge.cpp
./android/bridge/script/script_side_in_multi_so.cpp
./android/bridge/script/script_side_in_multi_process.cpp
./android/bridge/script_bridge_in_multi_so.cpp
./android/bridge/script_bridge_in_multi_process.cpp
./android/bridge/multi_process_and_so_initializer.cpp
./android/bridge/multi_so_initializer.cpp
./android/wrap/wml_bridge.cpp
./android/utils/cache_utils.cpp
./android/utils/params_utils.cpp
./android/utils/so_utils.cpp
./android/utils/IPCStringResult.cpp
./android/wrap/log_utils.cpp
./android/wrap/hash_set.cpp
./android/wrap/wx_map.cpp
./android/wrap/wx_js_object.cpp
./android/wrap/wx_bridge.cpp
./android/wrap/wx_params.cpp
./android/base/jni_type.cpp
./android/jsengine/multiprocess/WeexJSConnection.cpp
./android/jsengine/multiprocess/ExtendJSApi.cpp
)
SET(FINAL_ADD_LIBRARY
${FINAL_ADD_LIBRARY}
${ANDROID_SRCS}
)
SET(FINAL_TARGET_LINK_LIBRARIES
${FINAL_TARGET_LINK_LIBRARIES}
wson
android
weexipc
log
z
)
endif (ANDROID)
##if(iOS)
add_definitions(-DTARGET_OS_IPHONE=1)
##endif(iOS)
add_library(${WEEXCORE_LIBRARY_NAME} SHARED ${FINAL_ADD_LIBRARY})
target_include_directories(${WEEXCORE_LIBRARY_NAME} PUBLIC .)
target_link_libraries(${WEEXCORE_LIBRARY_NAME} ${FINAL_TARGET_LINK_LIBRARIES})
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCBUFFER_H
#define IPCBUFFER_H
#include <stddef.h>
// A buffer starts with msg.
class IPCBuffer {
public:
virtual ~IPCBuffer() = default;
virtual const void* get() = 0;
virtual size_t length() = 0;
};
#endif /* IPCBUFFER_H */
cmake_minimum_required(VERSION 3.4.1)
set(IPC_LIBRARY_NAME weexipc)
add_library(${IPC_LIBRARY_NAME} STATIC
./Serializing/IPCSerializer.cpp
./IPCResult.cpp
./IPCSender.cpp
./IPCException.cpp
./IPCCommunicator.cpp
./IPCHandler.cpp
./IPCListener.cpp
./IPCFutexPageQueue.cpp
./IPCFutexPageQueue.cpp
./ashmem.c
./IPCCheck.cpp
)
target_include_directories(${IPC_LIBRARY_NAME} PUBLIC .)
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCARGUMENTS_H
#define IPCARGUMENTS_H
#include "IPCType.h"
struct IPCString;
struct IPCByteArray;
class IPCArguments {
public:
virtual ~IPCArguments() = default;
template <typename T>
T get(int index)
{
return *static_cast<const T*>(getData(index));
}
const IPCString* getString(int index)
{
return static_cast<const IPCString*>(getData(index));
}
const IPCByteArray* getByteArray(int index)
{
return static_cast<const IPCByteArray*>(getData(index));
}
virtual const void* getData(int index) = 0;
virtual IPCType getType(int index) = 0;
virtual size_t getCount() = 0;
};
#endif /* IPCARGUMENTS_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCBYTEARRAY_H
#define IPCBYTEARRAY_H
#include <stddef.h>
struct IPCByteArray {
uint32_t length;
char content[1];
};
#endif /* IPCBYTEARRAY_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#if !defined(NDEBUG)
#include "IPCCheck.h"
#include <android/log.h>
#define TAG "linzj_IPC"
void reportCheckFailed(const char* msg, const char* file, int line)
{
__android_log_print(ANDROID_LOG_ERROR, TAG, msg, file, line);
__builtin_trap();
}
void reportUnreachable(const char* file, int line)
{
__android_log_print(ANDROID_LOG_ERROR, TAG, "unreachable statement reached %s %d", file, line);
__builtin_trap();
}
#endif
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCCHECK_H
#define IPCCHECK_H
#include <stdlib.h>
#if defined(NDEBUG)
#define IPC_DCHECK(b)
#define IPC_UNREACHABLE() abort()
#else
void reportCheckFailed(const char* msg, const char* file, int line);
void reportUnreachable(const char* file, int line);
#define IPC_DCHECK(b) \
if (!(b)) { \
reportCheckFailed("CHECK FAILED: " #b " at line %s %d", __FILE__, __LINE__); \
}
#define IPC_UNREACHABLE() reportUnreachable(__FILE__, __LINE__);
#endif
#endif /* IPCCHECK_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCCOMMUNICATOR_H
#define IPCCOMMUNICATOR_H
#include <memory>
class IPCResult;
class IPCArguments;
class IPCBuffer;
class IPCFutexPageQueue;
class IPCCommunicator {
protected:
explicit IPCCommunicator(IPCFutexPageQueue* futexPageQueue);
virtual ~IPCCommunicator();
std::unique_ptr<IPCResult> assembleResult();
std::unique_ptr<IPCArguments> assembleArguments();
std::unique_ptr<IPCBuffer> generateResultBuffer(IPCResult*);
void doSendBufferOnly(IPCBuffer* buffer);
uint32_t doReadPackage();
const char* getBlob();
void releaseBlob();
private:
void doSendBufferOnly(const void* data, size_t s);
size_t doSendBufferPage(const void* data, size_t s, size_t pageSize);
void doRecvBufferOnly(void* data, size_t s);
std::unique_ptr<char[]> m_package;
// weakref to a IPCFutexPageQueue object.
IPCFutexPageQueue* m_futexPageQueue;
};
#endif /* IPCCOMMUNICATOR_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include "IPCException.h"
#include <stdarg.h>
#include <string>
struct IPCException::IPCExceptionImpl {
std::string str;
};
IPCException::IPCException(const char* fmt, ...)
: m_impl(new IPCExceptionImpl)
{
va_list ap;
char buffer[256];
va_start(ap, fmt);
vsnprintf(buffer, 256, fmt, ap);
va_end(ap);
m_impl->str.assign(buffer);
}
IPCException::~IPCException()
{
}
IPCException::IPCException(IPCException&& ex)
{
m_impl = std::move(ex.m_impl);
}
const char* IPCException::msg() const
{
return m_impl->str.c_str();
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCEXCEPTION_H
#define IPCEXCEPTION_H
#include <memory>
class IPCException {
public:
IPCException(const char* fmt, ...);
~IPCException();
IPCException(IPCException&& ex);
const char* msg() const;
private:
struct IPCExceptionImpl;
std::unique_ptr<IPCExceptionImpl> m_impl;
};
#endif /* IPCEXCEPTION_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include "IPCFutexPageQueue.h"
#include "IPCCheck.h"
#include "IPCException.h"
#include "IPCLog.h"
#include "IPCType.h"
#include "futex.h"
#include <errno.h>
#include <sched.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
IPCFutexPageQueue::IPCFutexPageQueue(void* sharedMemory, size_t s, size_t id)
: m_currentWrite(id)
, m_currentRead(id ^ 1)
, m_pageSize(s / m_pagesCount)
, m_sharedMemory(sharedMemory)
, m_tid(gettid())
{
IPC_DCHECK(s == ipc_size);
IPC_LOGD("id: %zu", id);
for (int i = m_currentWrite; i < m_pagesCount; i += 2) {
uint32_t* data = static_cast<uint32_t*>(getPage(i));
data[1] |= m_finishTag;
}
lock(m_currentWrite, true);
}
IPCFutexPageQueue::~IPCFutexPageQueue()
{
// build a terminate msg.
uint32_t* data = static_cast<uint32_t*>(getPage(m_currentWrite));
data[1] = sizeof(uint32_t) * 2;
data[2] = MSG_TERMINATE;
data[3] = static_cast<uint32_t>(IPCType::END);
try {
unlock(m_currentWrite);
} catch (IPCException& e) {
IPC_LOGE("%s", e.msg());
}
munmap(m_sharedMemory, m_pageSize << 2);
}
void IPCFutexPageQueue::stepWrite()
{
IPC_LOGD("stepWrite");
clearFinishedTag();
size_t current = m_currentWrite;
m_currentWrite = step(m_currentWrite);
lock(m_currentWrite, true);
unlock(current);
}
void IPCFutexPageQueue::unlock(size_t id)
{
IPC_LOGD("unlock: %zu", id);
volatile uint32_t* pageStart = static_cast<volatile uint32_t*>(getPage(id));
uint32_t l = m_tid;
if (__atomic_compare_exchange_n(pageStart, &l, 0,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
return;
}
if ((l & FUTEX_WAITERS) != 0) {
int futexReturn = __futex(pageStart, FUTEX_UNLOCK_PI, 0, nullptr);
if (futexReturn == -1) {
throw IPCException("failed to futex unlock %s", strerror(errno));
}
return;
} else if ((l & FUTEX_TID_MASK) != m_tid) {
throw IPCException("l is not equal to tid: %d %d", l, m_tid);
}
throw IPCException("expected lock value");
}
void IPCFutexPageQueue::lock(size_t id, bool checkFinish)
{
volatile uint32_t* pageStart = static_cast<volatile uint32_t*>(getPage(id));
uint32_t l = m_tid;
uint32_t expected = 0;
IPC_LOGD("lock: %zu", id);
// wait for the finished tag;
if (checkFinish) {
while (true) {
uint32_t finishedTag = pageStart[1];
if (finishedTag == m_finishTag) {
break;
}
struct timespec waitTime = { m_timeoutSec, 0 };
int futexReturn = __futex(pageStart + 1, FUTEX_WAIT, 0, &waitTime);
if (futexReturn == -1) {
int myerrno = errno;
if (myerrno == EINTR)
continue;
else if (myerrno == ETIMEDOUT) {
throw IPCException("IPCFutexPageQueue::lock timeout when waiting for finished");
} else if (myerrno == EAGAIN) {
// become m_finishTag when enter the linux kernel.
break;
} else {
throw IPCException("IPCException::lock waiting for finished tag %u: %s", pageStart[1], strerror(myerrno));
}
}
break;
}
}
if (__atomic_compare_exchange_n(pageStart, &expected, l,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
return;
}
errno = 0;
while (true) {
int futexReturn = __futex(pageStart, FUTEX_LOCK_PI, 1, nullptr);
if (futexReturn == -1 && errno != EINTR) {
volatile uint32_t* pageStart0 = static_cast<volatile uint32_t*>(getPage(0));
volatile uint32_t* pageStart1 = static_cast<volatile uint32_t*>(getPage(1));
volatile uint32_t* pageStart2 = static_cast<volatile uint32_t*>(getPage(2));
volatile uint32_t* pageStart3 = static_cast<volatile uint32_t*>(getPage(3));
throw IPCException("futex lock pi failed: %s, %x %d (%x %x %x %x)", strerror(errno), *pageStart, m_tid, *pageStart0, *pageStart1, *pageStart2, *pageStart3);
}
if (futexReturn == -1)
continue;
break;
}
l = *pageStart;
if ((l & FUTEX_OWNER_DIED)) {
unlock(id);
throw IPCException("original owner has die");
}
}
void* IPCFutexPageQueue::getPage(size_t id)
{
size_t offset = id * m_pageSize;
return static_cast<char*>(m_sharedMemory) + offset;
}
void IPCFutexPageQueue::lockReadPage()
{
IPC_LOGD("lockReadPage");
uint32_t* pageStart = static_cast<uint32_t*>(getPage(m_currentRead));
if (!*pageStart) {
// this page should be locked.
}
lock(m_currentRead, false);
}
void IPCFutexPageQueue::unlockReadPageAndStep()
{
IPC_LOGD("unlockReadPageAndStep");
setFinishedTag();
unlock(m_currentRead);
m_currentRead = step(m_currentRead);
}
void IPCFutexPageQueue::spinWaitPeer()
{
volatile uint32_t* pageStart = static_cast<volatile uint32_t*>(getPage(m_currentRead));
struct timespec start;
clock_gettime(CLOCK_MONOTONIC, &start);
while (!*pageStart) {
sched_yield();
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if ((now.tv_sec - start.tv_sec) > m_timeoutSec)
throw IPCException("spinWaitPeer timeout");
}
}
void IPCFutexPageQueue::setFinishedTag()
{
uint32_t* pageStart = static_cast<uint32_t*>(getPage(m_currentRead));
uint32_t expected = 0;
if (__atomic_compare_exchange_n(pageStart + 1, &expected, m_finishTag,
false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
IPC_LOGD("setFinishedTag:waking writer");
__futex(pageStart + 1, FUTEX_WAKE, 1, nullptr);
return;
} else {
IPC_LOGD("setFinishedTag unexpected value: %u", expected);
}
}
void IPCFutexPageQueue::clearFinishedTag()
{
uint32_t* pageRead = static_cast<uint32_t*>(getPage(m_currentWrite));
pageRead[1] = 0;
__atomic_thread_fence(__ATOMIC_SEQ_CST);
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCFUTEXPAGEQUEUE_H
#define IPCFUTEXPAGEQUEUE_H
#include <stdint.h>
// shared memory page layout:
// futex uint32_t
// state word uint32_t
// package size uint32_t
// msg type uint32_t
// types[] uint32_t[]
//
// data whatever types indicate
// A page queue is composed of m_pagesCount pages
// and will use repeatedly.
class IPCFutexPageQueue {
public:
IPCFutexPageQueue(void* sharedMemory, size_t s, size_t id);
~IPCFutexPageQueue();
void stepWrite();
void lockReadPage();
void unlockReadPageAndStep();
void spinWaitPeer();
inline void* getCurrentReadPage() { return sizeof(uint32_t) * 2 + static_cast<char*>(getPage(m_currentRead)); }
inline void* getCurrentWritePage() { return sizeof(uint32_t) * 2 + static_cast<char*>(getPage(m_currentWrite)); }
inline size_t getPageSize() const { return m_pageSize - sizeof(uint32_t) * 2; }
static const size_t ipc_size = 2 * 1024 * 1024;
private:
void unlock(size_t id);
void lock(size_t id, bool checkFinish);
void* getPage(size_t id);
inline size_t step(size_t s) { return (s + 2) & (m_pagesCount - 1); }
void setFinishedTag();
void clearFinishedTag();
size_t m_currentWrite;
size_t m_currentRead;
size_t m_pageSize;
void* m_sharedMemory;
int m_tid;
static const uint32_t m_finishTag = static_cast<uint32_t>(1);
static const size_t m_pagesCount = 16;
static const int m_timeoutSec = 32;
};
#endif /* IPCFUTEXPAGEQUEUE_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include "IPCHandler.h"
#include "IPCLog.h"
#include "IPCResult.h"
#include <unordered_map>
namespace {
class IPCHandlerImpl : public IPCHandler {
public:
std::unique_ptr<IPCResult> handle(uint32_t msg, IPCArguments*) override;
void registerHandler(int msg, const std::function<std::unique_ptr<IPCResult>(IPCArguments*)>& handler) override;
private:
typedef std::unordered_map<int, std::function<std::unique_ptr<IPCResult>(IPCArguments*)>> MapType;
MapType m_map;
};
std::unique_ptr<IPCResult> IPCHandlerImpl::handle(uint32_t msg, IPCArguments* arguments)
{
auto it = m_map.find(msg);
if (it == m_map.end()) {
IPC_LOGE("unable to find msg: %d", msg);
return createVoidResult();
}
return it->second(arguments);
}
void IPCHandlerImpl::registerHandler(int msg, const std::function<std::unique_ptr<IPCResult>(IPCArguments*)>& handler)
{
m_map.insert(MapType::value_type(msg, handler));
}
}
std::unique_ptr<IPCHandler> createIPCHandler()
{
return std::unique_ptr<IPCHandler>(new IPCHandlerImpl);
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCHANDLER_H
#define IPCHANDLER_H
#include <functional>
#include <memory>
#include <stdint.h>
class IPCResult;
class IPCArguments;
class IPCHandler {
public:
virtual ~IPCHandler() = default;
virtual std::unique_ptr<IPCResult> handle(uint32_t msg, IPCArguments*) = 0;
virtual void registerHandler(int msg, const std::function<std::unique_ptr<IPCResult>(IPCArguments*)>& handler) = 0;
};
std::unique_ptr<IPCHandler> createIPCHandler();
#endif /* IPCHANDLER_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include "IPCListener.h"
#include "Buffering/IPCBuffer.h"
#include "IPCArguments.h"
#include "IPCCommunicator.h"
#include "IPCException.h"
#include "IPCHandler.h"
#include "IPCResult.h"
#include "IPCType.h"
#include <unistd.h>
namespace {
class IPCListenerImpl : public IPCCommunicator,
public IPCListener {
public:
IPCListenerImpl(IPCFutexPageQueue* futexPageQueue, IPCHandler* handler);
~IPCListenerImpl() override;
void listen() override;
private:
int m_fd;
IPCHandler* m_handler;
};
IPCListenerImpl::IPCListenerImpl(IPCFutexPageQueue* futexPageQueue, IPCHandler* handler)
: IPCCommunicator(futexPageQueue)
, m_handler(handler)
{
}
IPCListenerImpl::~IPCListenerImpl()
{
}
void IPCListenerImpl::listen()
{
while (true) {
uint32_t msg = doReadPackage();
bool isAsync = !!(msg & MSG_FLAG_ASYNC);
msg &= MSG_MASK;
if (msg == MSG_END)
throw IPCException("unexpected MSG_END");
else if (msg == MSG_TERMINATE) {
releaseBlob();
throw IPCException("peer terminates");
}
std::unique_ptr<IPCArguments> arguments = assembleArguments();
releaseBlob();
IPCArguments* pArguments = arguments.get();
std::unique_ptr<IPCResult> sendBack = m_handler->handle(msg, pArguments);
if (!isAsync) {
std::unique_ptr<IPCBuffer> resultBuffer = generateResultBuffer(sendBack.get());
doSendBufferOnly(resultBuffer.get());
}
}
}
}
std::unique_ptr<IPCListener> createIPCListener(IPCFutexPageQueue* futexPageQueue, IPCHandler* handler)
{
return std::unique_ptr<IPCListener>(new IPCListenerImpl(futexPageQueue, handler));
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCLISTENER_H
#define IPCLISTENER_H
#include <memory>
class IPCHandler;
class IPCFutexPageQueue;
class IPCListener {
public:
virtual ~IPCListener() = default;
virtual void listen() = 0;
};
std::unique_ptr<IPCListener> createIPCListener(IPCFutexPageQueue*, IPCHandler* handler);
#endif /* IPCLISTENER_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCLOG_H
#define IPCLOG_H
#include <android/log.h>
#define TAG "linzj_IPC"
#define IPC_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
#if defined(ENABLE_IPC_DEBUG_LOG) && ENABLE_IPC_DEBUG_LOG
#define IPC_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#else
#define IPC_LOGD(...)
#endif
#endif /* IPCLOG_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCMESSAGEJS_H
#define IPCMESSAGEJS_H
// Message from Platform to Script in ScriptBridge
enum class IPCJSMsg {
INITFRAMEWORK,
EXECJSSERVICE,
TAKEHEAPSNAPSHOT,
EXECJS,
CREATEINSTANCE,
DESTORYINSTANCE,
EXECJSONINSTANCE,
EXECJSWITHRESULT,
EXECJSWITHCALLBACK,
UPDATEGLOBALCONFIG,
EXECTIMERCALLBACK,
INITAPPFRAMEWORK,
CREATEAPPCONTEXT,
EXECJSONAPPWITHRESULT,
CALLJSONAPPCONTEXT,
DESTORYAPPCONTEXT,
};
// Message from Script to Core in ScriptBridge
enum class IPCProxyMsg {
SETJSFVERSION,
REPORTEXCEPTION,
CALLNATIVE,
CALLNATIVEMODULE,
CALLNATIVECOMPONENT,
CALLADDELEMENT,
SETTIMEOUT,
NATIVELOG,
CALLCREATEBODY,
CALLUPDATEFINISH,
CALLCREATEFINISH,
CALLREFRESHFINISH,
CALLUPDATEATTRS,
CALLUPDATESTYLE,
CALLREMOVEELEMENT,
CALLMOVEELEMENT,
CALLADDEVENT,
CALLREMOVEEVENT,
CALLGCANVASLINK,
CALLT3DLINK,
SETINTERVAL,
CLEARINTERVAL,
POSTMESSAGE,
DISPATCHMESSAGE,
ONRECEIVEDRESULT,
};
// Message from Script to Core in ScriptBridge
// Message from Core to Platform in PlatformBridge
enum class IPCMsgFromCoreToPlatform {
INVOKE_MEASURE_FUNCTION = 100,
INVOKE_LAYOUT_BEFORE,
INVOKE_LAYOUT_AFTER,
SET_JS_VERSION,
REPORT_EXCEPTION,
CALL_NATIVE,
CALL_NATIVE_MODULE,
CALL_NATIVE_COMPONENT,
SET_TIMEOUT,
NATIVE_LOG,
UPDATE_FINISH,
REFRESH_FINISH,
ADD_EVENT,
REMOVE_EVENT,
CREATE_BODY,
ADD_ELEMENT,
LAYOUT,
UPDATE_STYLE,
UPDATE_ATTR,
CREATE_FINISH,
RENDER_SUCCESS,
REMOVE_ELEMENT,
MOVE_ELEMENT,
APPEND_TREE_CREATE_FINISH,
HAS_TRANSITION_PROS,
POST_MESSAGE,
DISPATCH_MESSAGE
};
// Message from Platform to Core in PlatformBridge
enum class IPCMsgFromPlatformToCore {
SET_DEFAULT_HEIGHT_AND_WIDTH_INTO_ROOT_DOM = 100,
ON_INSTANCE_CLOSE,
SET_STYLE_WIDTH,
SET_STYLE_HEIGHT,
SET_MARGIN,
SET_PADDING,
SET_POSITION,
MARK_DIRTY,
SET_VIEWPORT_WIDTH,
FORCE_LAYOUT,
NOTIFY_LAYOUT,
GET_FIRST_SCREEN_RENDER_TIME,
GET_RENDER_FINISH_TIME,
SET_RENDER_CONTAINER_WRAP_CONTENT,
BIND_MEASUREMENT_TO_RENDER_OBJECT,
REGISTER_CORE_ENV,
GET_RENDER_OBJECT,
UPDATE_RENDER_OBJECT_STYLE,
UPDATE_RENDER_OBJECT_ATTR,
COPY_RENDER_OBJECT,
SET_MEASURE_FUNCTION_ADAPTER,
SET_PLATFORM,
SET_DEVICE_WIDTH_AND_HEIGHT,
ADD_OPTION,
INIT_FRAMEWORK,
INIT_APP_FRAMEWORK,
CREATE_APP_CONTEXT,
EXEC_JS_ON_APP_WITH_RESULT,
CALL_JS_ON_APP_CONTEXT,
DESTROY_APP_CONTEXT,
EXEC_JS_SERVICE,
EXEC_TIME_CALLBACK,
EXEC_JS,
EXEC_JS_WITH_RESULT,
CREATE_INSTANCE,
EXEC_JS_ON_INSTANCE,
DESTROY_INSTANCE,
UPDATE_GLOBAL_CONFIG
};
#endif /* IPCMESSAGEJS_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include "IPCResult.h"
#include <cstdlib>
namespace {
class VoidResult : public IPCResult {
public:
const void* getData() override;
IPCType getType() override;
const uint16_t* getStringContent() override;
size_t getStringLength() override;
const char* getByteArrayContent() override;
size_t getByteArrayLength() override;
};
template <typename T>
struct TypeTrait {
};
template <>
struct TypeTrait<int32_t> {
static const IPCType s_type = IPCType::INT32;
};
template <>
struct TypeTrait<int64_t> {
static const IPCType s_type = IPCType::INT64;
};
template <>
struct TypeTrait<double> {
static const IPCType s_type = IPCType::DOUBLE;
};
template <typename T>
class ValueResult : public IPCResult {
public:
explicit ValueResult(T val);
const void* getData() override;
IPCType getType() override;
const uint16_t* getStringContent() override;
size_t getStringLength() override;
const char* getByteArrayContent() override;
size_t getByteArrayLength() override;
private:
typedef T value_type;
typedef TypeTrait<value_type> trait_type;
value_type m_value;
static const IPCType s_type = trait_type::s_type;
};
class ByteArrayResult: public IPCResult{
public:
ByteArrayResult(const char* data, size_t length);
~ByteArrayResult();
const void* getData() override;
IPCType getType() override;
const uint16_t* getStringContent() override;
size_t getStringLength() override;
const char* getByteArrayContent() override;
size_t getByteArrayLength() override;
private:
char* m_data;
size_t m_length;
};
const void*
VoidResult::getData()
{
return nullptr;
}
IPCType VoidResult::getType()
{
return IPCType::VOID;
}
const uint16_t* VoidResult::getStringContent()
{
return nullptr;
}
size_t VoidResult::getStringLength()
{
return 0U;
}
const char* VoidResult::getByteArrayContent()
{
return nullptr;
}
size_t VoidResult::getByteArrayLength()
{
return 0U;
}
template <typename T>
ValueResult<T>::ValueResult(T val)
: m_value(val)
{
}
template <typename T>
const void* ValueResult<T>::getData()
{
return &m_value;
}
template <typename T>
IPCType ValueResult<T>::getType()
{
return s_type;
}
template <typename T>
const uint16_t* ValueResult<T>::getStringContent()
{
return nullptr;
}
template <typename T>
size_t ValueResult<T>::getStringLength()
{
return 0U;
}
template <typename T>
const char* ValueResult<T>::getByteArrayContent()
{
return nullptr;
}
template <typename T>
size_t ValueResult<T>::getByteArrayLength()
{
return 0U;
}
ByteArrayResult::ByteArrayResult(const char* data, size_t length):m_length(length)
{
if(length > 0){
m_data = (char*)malloc(length*sizeof(char));
memcpy(m_data, data, length);
}else{
m_data = nullptr;
}
}
IPCType ByteArrayResult::getType()
{
return IPCType::BYTEARRAY;
}
const void* ByteArrayResult::getData()
{
return nullptr;
}
const uint16_t* ByteArrayResult::getStringContent(){
return nullptr;
}
size_t ByteArrayResult::getStringLength(){
return 0l;
}
const char* ByteArrayResult::getByteArrayContent(){
return m_data;
}
size_t ByteArrayResult::getByteArrayLength(){
return m_length;
}
ByteArrayResult::~ByteArrayResult()
{
if (m_data){
free(m_data);
m_data= NULL;
}
m_length = 0;
}
}
std::unique_ptr<IPCResult> createVoidResult()
{
return std::unique_ptr<IPCResult>(new VoidResult);
}
std::unique_ptr<IPCResult> createInt32Result(int32_t val)
{
return std::unique_ptr<IPCResult>(new ValueResult<int32_t>(val));
}
std::unique_ptr<IPCResult> createInt64Result(int64_t val)
{
return std::unique_ptr<IPCResult>(new ValueResult<int64_t>(val));
}
std::unique_ptr<IPCResult> createDoubleResult(double val)
{
return std::unique_ptr<IPCResult>(new ValueResult<double>(val));
}
std::unique_ptr<IPCResult> createByteArrayResult(const char* data, size_t length){
return std::unique_ptr<IPCResult>(new ByteArrayResult(data, length));
}
class CharArrayResult : public IPCResult {
public:
CharArrayResult(char* chars);
// ByteArrayResult(const char* data);
~CharArrayResult();
const void* getData() override;
IPCType getType() override;
const uint16_t* getStringContent() override;
size_t getStringLength() override;
const char* getByteArrayContent() override;
size_t getByteArrayLength() override;
private:
char* m_char;
size_t m_length{ 0U };
};
CharArrayResult::CharArrayResult(char* chars)
: m_char(chars) {
m_length = strlen(m_char);
}
CharArrayResult::~CharArrayResult() {
delete[] m_char;
}
const void* CharArrayResult::getData()
{
return m_char;
}
IPCType CharArrayResult::getType()
{
return IPCType::CHARARRAY;
}
const uint16_t* CharArrayResult::getStringContent()
{
return nullptr;
}
size_t CharArrayResult::getStringLength()
{
return m_length;
}
const char* CharArrayResult::getByteArrayContent() {
return nullptr;
}
size_t CharArrayResult::getByteArrayLength() {
return 0U;
}
std::unique_ptr<IPCResult> createCharArrayResult(char* bytes) {
return std::unique_ptr<IPCResult>(new CharArrayResult(bytes));
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCRESULT_H
#define IPCRESULT_H
#include "IPCType.h"
#include <memory>
#include "IPCByteArray.h"
struct IPCString;
class IPCResult {
public:
virtual ~IPCResult() = default;
template <typename T>
T get()
{
return *static_cast<const T*>(getData());
}
virtual const void* getData() = 0;
virtual IPCType getType() = 0;
virtual const uint16_t* getStringContent() = 0;
virtual size_t getStringLength() = 0;
virtual const char* getByteArrayContent() = 0;
virtual size_t getByteArrayLength() = 0;
};
std::unique_ptr<IPCResult> createVoidResult();
std::unique_ptr<IPCResult> createInt32Result(int32_t val);
std::unique_ptr<IPCResult> createInt64Result(int64_t val);
std::unique_ptr<IPCResult> createDoubleResult(double val);
std::unique_ptr<IPCResult> createCharArrayResult(char* bytes);
std::unique_ptr<IPCResult> createByteArrayResult(const char* data, size_t length);
#endif /* IPCRESULT_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include "IPCSender.h"
#include "Buffering/IPCBuffer.h"
#include "IPCArguments.h"
#include "IPCByteArray.h"
#include "IPCCheck.h"
#include "IPCCommunicator.h"
#include "IPCException.h"
#include "IPCHandler.h"
#include "IPCResult.h"
#include "IPCString.h"
#include "Serializing/IPCSerializer.h"
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <vector>
namespace {
class IPCSenderImpl : public IPCCommunicator, public IPCSender {
public:
IPCSenderImpl(IPCFutexPageQueue*, IPCHandler* handler);
~IPCSenderImpl();
std::unique_ptr<IPCResult> send(IPCBuffer*) override;
private:
bool checkBufferAsync(IPCBuffer* buffer);
IPCHandler* m_handler;
};
IPCSenderImpl::IPCSenderImpl(IPCFutexPageQueue* futexPageQueue, IPCHandler* handler)
: IPCCommunicator(futexPageQueue)
, m_handler(handler)
{
}
IPCSenderImpl::~IPCSenderImpl()
{
}
std::unique_ptr<IPCResult> IPCSenderImpl::send(IPCBuffer* buffer)
{
doSendBufferOnly(buffer);
if (checkBufferAsync(buffer))
return createVoidResult();
while (true) {
uint32_t msg = doReadPackage();
bool isAsync = !!(msg & MSG_FLAG_ASYNC);
msg &= MSG_MASK;
if (msg == MSG_END) {
std::unique_ptr<IPCResult> result = assembleResult();
releaseBlob();
return result;
} else if (msg == MSG_TERMINATE) {
releaseBlob();
throw IPCException("peer terminates");
}
std::unique_ptr<IPCArguments> arguments = assembleArguments();
releaseBlob();
std::unique_ptr<IPCResult> sendBack = m_handler->handle(msg, arguments.get());
if (!isAsync) {
std::unique_ptr<IPCBuffer> resultBuffer = generateResultBuffer(sendBack.get());
doSendBufferOnly(resultBuffer.get());
}
}
}
bool IPCSenderImpl::checkBufferAsync(IPCBuffer* buffer)
{
uint32_t msg = *static_cast<const uint32_t*>(buffer->get());
return !!(msg & MSG_FLAG_ASYNC);
}
}
std::unique_ptr<IPCSender> createIPCSender(IPCFutexPageQueue* futexPageQueue, IPCHandler* handler)
{
return std::unique_ptr<IPCSender>(new IPCSenderImpl(futexPageQueue, handler));
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCSENDER_H
#define IPCSENDER_H
#include <memory>
class IPCBuffer;
class IPCResult;
class IPCHandler;
class IPCFutexPageQueue;
class IPCSender {
public:
virtual ~IPCSender() = default;
virtual std::unique_ptr<IPCResult> send(IPCBuffer* buffer) = 0;
};
std::unique_ptr<IPCSender> createIPCSender(IPCFutexPageQueue*, IPCHandler* handler);
#endif /* IPCSENDER_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCSTRING_H
#define IPCSTRING_H
struct IPCString {
uint32_t length;
uint16_t content[1];
};
#endif /* IPCSTRING_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCTYPE_H
#define IPCTYPE_H
#include <stdint.h>
struct IPCPackage {
uint32_t packageSize;
uint32_t msg;
uint32_t type[1];
};
enum class IPCType {
INT32,
INT64,
FLOAT,
DOUBLE,
JSONSTRING,
STRING,
BYTEARRAY, /* terminated with zero. */
CHARARRAY,
VOID,
JSUNDEFINED,
END,
};
static const uint32_t MSG_MASK = (1U << 31) - 1;
static const uint32_t MSG_END = static_cast<uint32_t>(-1) & MSG_MASK;
static const uint32_t MSG_TERMINATE = static_cast<uint32_t>(-2) & MSG_MASK;
static const uint32_t MSG_NOT_SET = static_cast<uint32_t>(-3) & MSG_MASK;
static const uint32_t MSG_FLAG_ASYNC = 1U << 31;
#endif /* IPCTYPE_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include "IPCSerializer.h"
#include "../Buffering/IPCBuffer.h"
#include "../IPCByteArray.h"
#include "../IPCCheck.h"
#include "../IPCString.h"
#include "../IPCType.h"
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
namespace {
class IPCSerializerImpl : public IPCSerializer {
public:
void setMsg(uint32_t msg) override;
void add(int32_t) override;
void add(int64_t) override;
void add(float) override;
void add(double) override;
void add(const uint16_t* data, size_t len) override;
void addJSON(const uint16_t* data, size_t len) override;
void add(const char* data, size_t len) override;
void add(const IPCByteArray* bytes) override;
void addJSUndefined() override;
void addVoid() override;
std::unique_ptr<IPCBuffer> finish() override;
private:
uint32_t m_msg{ MSG_END };
std::vector<uint32_t> m_types;
std::vector<std::unique_ptr<char[]>> m_datas;
};
class StringBasedIPCBufferImpl : public IPCBuffer {
public:
explicit StringBasedIPCBufferImpl(std::string&& s);
const void* get() override;
size_t length() override;
private:
std::string m_str;
};
void IPCSerializerImpl::setMsg(uint32_t msg)
{
m_msg = msg;
}
void IPCSerializerImpl::add(int32_t n)
{
std::unique_ptr<char[]> buffer(new char[sizeof(n)]);
*reinterpret_cast<int32_t*>(buffer.get()) = n;
m_types.emplace_back(static_cast<uint32_t>(IPCType::INT32));
m_datas.emplace_back(std::move(buffer));
}
void IPCSerializerImpl::add(int64_t n)
{
std::unique_ptr<char[]> buffer(new char[sizeof(n)]);
*reinterpret_cast<int64_t*>(buffer.get()) = n;
m_types.emplace_back(static_cast<uint32_t>(IPCType::INT64));
m_datas.emplace_back(std::move(buffer));
}
void IPCSerializerImpl::add(float n)
{
std::unique_ptr<char[]> buffer(new char[sizeof(n)]);
*reinterpret_cast<float*>(buffer.get()) = n;
m_types.emplace_back(static_cast<uint32_t>(IPCType::FLOAT));
m_datas.emplace_back(std::move(buffer));
}
void IPCSerializerImpl::add(double n)
{
std::unique_ptr<char[]> buffer(new char[sizeof(n)]);
*reinterpret_cast<double*>(buffer.get()) = n;
m_types.emplace_back(static_cast<uint32_t>(IPCType::DOUBLE));
m_datas.emplace_back(std::move(buffer));
}
void IPCSerializerImpl::add(const uint16_t* data, size_t len)
{
size_t byteLength = len * sizeof(uint16_t);
std::unique_ptr<char[]> buffer(new char[byteLength + sizeof(IPCString)]);
IPCString* s = reinterpret_cast<IPCString*>(buffer.get());
s->length = len;
memcpy(s->content, data, byteLength);
m_types.emplace_back(static_cast<uint32_t>(IPCType::STRING));
m_datas.emplace_back(std::move(buffer));
}
void IPCSerializerImpl::addJSON(const uint16_t* data, size_t len)
{
size_t byteLength = len * sizeof(uint16_t);
std::unique_ptr<char[]> buffer(new char[byteLength + sizeof(IPCString)]);
IPCString* s = reinterpret_cast<IPCString*>(buffer.get());
s->length = len;
memcpy(s->content, data, byteLength);
m_types.emplace_back(static_cast<uint32_t>(IPCType::JSONSTRING));
m_datas.emplace_back(std::move(buffer));
}
void IPCSerializerImpl::add(const char* data, size_t len)
{
size_t byteLength = len;
std::unique_ptr<char[]> buffer(new char[byteLength + sizeof(IPCByteArray)]);
IPCByteArray* s = reinterpret_cast<IPCByteArray*>(buffer.get());
s->length = len;
memcpy(s->content, data, byteLength);
s->content[byteLength] = '\0';
m_types.emplace_back(static_cast<uint32_t>(IPCType::BYTEARRAY));
m_datas.emplace_back(std::move(buffer));
}
void IPCSerializerImpl::add(const IPCByteArray* bytes) {
m_types.emplace_back(static_cast<uint32_t>(IPCType::BYTEARRAY));
// m_datas.emplace_back(std::move((std::unique_ptr<char[]>)bytes));
}
void IPCSerializerImpl::addJSUndefined()
{
m_types.emplace_back(static_cast<uint32_t>(IPCType::JSUNDEFINED));
m_datas.emplace_back();
}
void IPCSerializerImpl::addVoid()
{
m_types.emplace_back(static_cast<uint32_t>(IPCType::VOID));
m_datas.emplace_back();
}
std::unique_ptr<IPCBuffer> IPCSerializerImpl::finish()
{
IPC_DCHECK(m_types.size() > 0);
IPC_DCHECK(m_msg != MSG_NOT_SET);
std::ostringstream oss;
oss.write(reinterpret_cast<const char*>(&m_msg), sizeof(m_msg));
for (auto& type : m_types) {
oss.write(reinterpret_cast<const char*>(&type), sizeof(type));
}
uint32_t endOfType = static_cast<uint32_t>(IPCType::END);
oss.write(reinterpret_cast<const char*>(&endOfType), sizeof(endOfType));
int i = 0;
for (auto& data : m_datas) {
switch (static_cast<IPCType>(m_types[i])) {
case IPCType::INT32: {
oss.write(data.get(), sizeof(int32_t));
} break;
case IPCType::INT64: {
oss.write(data.get(), sizeof(int64_t));
} break;
case IPCType::FLOAT: {
oss.write(data.get(), sizeof(float));
} break;
case IPCType::DOUBLE: {
oss.write(data.get(), sizeof(double));
} break;
case IPCType::BYTEARRAY: {
IPCByteArray* a = reinterpret_cast<IPCByteArray*>(data.get());
size_t byteLength = a->length;
oss.write(reinterpret_cast<const char*>(&a->length), sizeof(a->length));
oss.write(reinterpret_cast<const char*>(a->content), byteLength);
} break;
case IPCType::JSONSTRING:
case IPCType::STRING: {
IPCString* s = reinterpret_cast<IPCString*>(data.get());
size_t byteLength = s->length * sizeof(uint16_t);
oss.write(reinterpret_cast<const char*>(&s->length), sizeof(s->length));
oss.write(reinterpret_cast<const char*>(s->content), byteLength);
} break;
case IPCType::JSUNDEFINED:
case IPCType::VOID:
break;
default:
IPC_UNREACHABLE();
}
++i;
}
m_types.clear();
m_datas.clear();
m_msg = MSG_NOT_SET;
std::unique_ptr<StringBasedIPCBufferImpl> bufferReturn(new StringBasedIPCBufferImpl(std::move(oss.str())));
return std::unique_ptr<IPCBuffer>(bufferReturn.release());
}
StringBasedIPCBufferImpl::StringBasedIPCBufferImpl(std::string&& s)
: m_str(std::move(s))
{
}
const void* StringBasedIPCBufferImpl::get()
{
return m_str.data();
}
size_t StringBasedIPCBufferImpl::length()
{
return m_str.length();
}
}
std::unique_ptr<IPCSerializer> createIPCSerializer()
{
return std::unique_ptr<IPCSerializer>(new IPCSerializerImpl);
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef IPCSERIALIZER_H
#define IPCSERIALIZER_H
#include <memory>
#include <stdint.h>
#include "IPCByteArray.h"
class IPCBuffer;
class IPCSerializer {
public:
virtual ~IPCSerializer() = default;
virtual void setMsg(uint32_t msg) = 0;
virtual void add(int32_t) = 0;
virtual void add(int64_t) = 0;
virtual void add(float) = 0;
virtual void add(double) = 0;
virtual void add(const uint16_t* data, size_t len) = 0;
virtual void addJSON(const uint16_t* data, size_t len) = 0;
virtual void add(const char* data, size_t len) = 0;
virtual void add(const IPCByteArray* bytes) = 0;
virtual void addJSUndefined() = 0;
virtual void addVoid() = 0;
virtual std::unique_ptr<IPCBuffer> finish() = 0;
};
std::unique_ptr<IPCSerializer> createIPCSerializer();
#endif /* IPCSERIALIZER_H */
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "ashmem.h"
#include <linux/ashmem.h>
#define ASHMEM_DEVICE "/dev/ashmem"
/*
* ashmem_create_region - creates a new ashmem region and returns the file
* descriptor, or <0 on error
*
* `name' is an optional label to give the region (visible in /proc/pid/maps)
* `size' is the size of the region, in page-aligned bytes
*/
int ashmem_create_region(const char* name, size_t size)
{
int fd, ret;
fd = open(ASHMEM_DEVICE, O_RDWR);
if (fd < 0)
return fd;
if (name) {
char buf[ASHMEM_NAME_LEN];
strlcpy(buf, name, sizeof(buf));
ret = ioctl(fd, ASHMEM_SET_NAME, buf);
if (ret < 0)
goto error;
}
ret = ioctl(fd, ASHMEM_SET_SIZE, size);
if (ret < 0)
goto error;
return fd;
error:
close(fd);
return ret;
}
int ashmem_set_prot_region(int fd, int prot)
{
return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);
}
int ashmem_pin_region(int fd, size_t offset, size_t len)
{
struct ashmem_pin pin = { offset, len };
return ioctl(fd, ASHMEM_PIN, &pin);
}
int ashmem_unpin_region(int fd, size_t offset, size_t len)
{
struct ashmem_pin pin = { offset, len };
return ioctl(fd, ASHMEM_UNPIN, &pin);
}
int ashmem_get_size_region(int fd)
{
return ioctl(fd, ASHMEM_GET_SIZE, NULL);
}
int ashmem_purge_all(void)
{
const int fd = open(ASHMEM_DEVICE, O_RDWR);
if (fd < 0)
return fd;
const int ret = ioctl(fd, ASHMEM_PURGE_ALL_CACHES, 0);
close(fd);
return ret;
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* 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.
*/
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
* used by the simulator.
*/
#ifndef _THIRD_PARTY_ASHMEM_H
#define _THIRD_PARTY_ASHMEM_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
int ashmem_create_region(const char* name, size_t size);
int ashmem_set_prot_region(int fd, int prot);
int ashmem_pin_region(int fd, size_t offset, size_t len);
int ashmem_unpin_region(int fd, size_t offset, size_t len);
int ashmem_get_size_region(int fd);
int ashmem_purge_all(void);
#ifdef __cplusplus
}
#endif
#ifndef __ASHMEMIOC /* in case someone included <linux/ashmem.h> too */
#define ASHMEM_NAME_LEN 256
#define ASHMEM_NAME_DEF "dev/ashmem"
/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */
#define ASHMEM_NOT_PURGED 0
#define ASHMEM_WAS_PURGED 1
/* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */
#define ASHMEM_IS_UNPINNED 0
#define ASHMEM_IS_PINNED 1
#endif /* ! __ASHMEMIOC */
#endif /* _THIRD_PARTY_ASHMEM_H */
/*
* Copyright (C) 2008 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _BIONIC_FUTEX_H
#define _BIONIC_FUTEX_H
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/cdefs.h>
#include <sys/syscall.h>
#include <unistd.h>
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
#define FUTEX_FD 2
#define FUTEX_REQUEUE 3
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define FUTEX_CMP_REQUEUE 4
#define FUTEX_WAKE_OP 5
#define FUTEX_LOCK_PI 6
#define FUTEX_UNLOCK_PI 7
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define FUTEX_TRYLOCK_PI 8
#define FUTEX_WAIT_BITSET 9
#define FUTEX_WAKE_BITSET 10
#define FUTEX_WAIT_REQUEUE_PI 11
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define FUTEX_CMP_REQUEUE_PI 12
#define FUTEX_PRIVATE_FLAG 128
#define FUTEX_CLOCK_REALTIME 256
#define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
#define FUTEX_TID_MASK 0x3fffffff
#define FUTEX_OWNER_DIED 0x40000000
#define FUTEX_WAITERS 0x80000000
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
#define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define FUTEX_WAKE_OP_PRIVATE (FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG)
#define FUTEX_LOCK_PI_PRIVATE (FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG)
#define FUTEX_UNLOCK_PI_PRIVATE (FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG)
#define FUTEX_TRYLOCK_PI_PRIVATE (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG)
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define FUTEX_WAIT_BITSET_PRIVATE (FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_BITSET_PRIVATE (FUTEX_WAKE_BITSET | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAIT_REQUEUE_PI_PRIVATE (FUTEX_WAIT_REQUEUE_PI | FUTEX_PRIVATE_FLAG)
#define FUTEX_CMP_REQUEUE_PI_PRIVATE (FUTEX_CMP_REQUEUE_PI | FUTEX_PRIVATE_FLAG)
#ifndef __predict_false
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
#endif // __predict_false
struct timespec;
static inline __always_inline int __futex(volatile void* ftx, int op, int value, const struct timespec* timeout)
{
// Our generated syscall assembler sets errno, but our callers (pthread functions) don't want to.
int result = syscall(__NR_futex, ftx, op, value, timeout);
return result;
}
static inline int __futex_wake(volatile void* ftx, int count)
{
return __futex(ftx, FUTEX_WAKE, count, NULL);
}
static inline int __futex_wake_ex(volatile void* ftx, bool shared, int count)
{
return __futex(ftx, shared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, count, NULL);
}
static inline int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout)
{
return __futex(ftx, FUTEX_WAIT, value, timeout);
}
static inline int __futex_wait_ex(volatile void* ftx, bool shared, int value, const struct timespec* timeout)
{
return __futex(ftx, shared ? FUTEX_WAIT : FUTEX_WAIT_PRIVATE, value, timeout);
}
#endif /* _BIONIC_FUTEX_H */
/**
* \file
* <PRE>
* High performance base64 encoder / decoder
* Version 1.3 -- 17-Mar-2006
*
* Copyright &copy; 2005, 2006, Nick Galbreath -- nickg [at] modp [dot] com
* All rights reserved.
*
* http://modp.com/release/base64
*
* Released under bsd license. See modp_b64.c for details.
* </pre>
*
* The default implementation is the standard b64 encoding with padding.
* It's easy to change this to use "URL safe" characters and to remove
* padding. See the modp_b64.c source code for details.
*
*/
#include "./base64.h"
#include <string.h>
bool Base64Encode(const std::string &input, std::string *output) {
std::string temp;
temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte
// null terminates result since result is base64 text!
int input_size = static_cast<int>(input.size());
int output_size = modp_b64_encode(&(temp[0]), input.data(), input_size);
if (output_size < 0)
return false;
temp.resize(output_size); // strips off null byte
output->swap(temp);
return true;
}
bool Base64Decode(const std::string &input, std::string *output) {
std::string temp;
temp.resize(modp_b64_decode_len(input.size()));
// does not null terminate result since result is binary data!
int input_size = static_cast<int>(input.size());
int output_size = modp_b64_decode(&(temp[0]), input.data(), input_size);
if (output_size < 0)
return false;
temp.resize(output_size);
output->swap(temp);
return true;
}
\ No newline at end of file
/**
* \file
* <PRE>
* High performance base64 encoder / decoder
* Version 1.3 -- 17-Mar-2006
*
* Copyright &copy; 2005, 2006, Nick Galbreath -- nickg [at] modp [dot] com
* All rights reserved.
*
* http://modp.com/release/base64
*
* Released under bsd license. See modp_b64.c for details.
* </pre>
*
* The default implementation is the standard b64 encoding with padding.
* It's easy to change this to use "URL safe" characters and to remove
* padding. See the modp_b64.c source code for details.
*
*/
#include "./modp_base64/modp_b64.h"
// Encodes the input string in base64. Returns true if successful and false
// otherwise. The output string is only modified if successful.
bool Base64Encode(const std::string &input, std::string *output);
// Decodes the base64 input string. Returns true if successful and false
// otherwise. The output string is only modified if successful.
bool Base64Decode(const std::string &input, std::string *output);
/**
* \file
* <PRE>
* High performance base64 encoder / decoder
* Version 1.3 -- 17-Mar-2006
*
* Copyright &copy; 2005, 2006, Nick Galbreath -- nickg [at] modp [dot] com
* All rights reserved.
*
* http://modp.com/release/base64
*
* Released under bsd license. See modp_b64.c for details.
* </pre>
*
* The default implementation is the standard b64 encoding with padding.
* It's easy to change this to use "URL safe" characters and to remove
* padding. See the modp_b64.c source code for details.
*
*/
/* public header */
#include "modp_b64.h"
/*
* If you are ripping this out of the library, comment out the next
* line and uncomment the next lines as approrpiate
*/
//#include "config.h"
/* if on motoral, sun, ibm; uncomment this */
/* #define WORDS_BIGENDIAN 1 */
/* else for Intel, Amd; uncomment this */
/* #undef WORDS_BIGENDIAN */
#include "modp_b64_data.h"
#define BADCHAR 0x01FFFFFF
/**
* you can control if we use padding by commenting out this
* next line. However, I highly recommend you use padding and not
* using it should only be for compatability with a 3rd party.
* Also, 'no padding' is not tested!
*/
#define DOPAD 1
/*
* if we aren't doing padding
* set the pad character to NULL
*/
#ifndef DOPAD
#undef CHARPAD
#define CHARPAD '\0'
#endif
int modp_b64_encode(char *dest, const char *str, int len) {
int i;
uint8_t *p = (uint8_t *) dest;
/* unsigned here is important! */
uint8_t t1, t2, t3;
for (i = 0; i < len - 2; i += 3) {
t1 = str[i];
t2 = str[i + 1];
t3 = str[i + 2];
*p++ = e0[t1];
*p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
*p++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
*p++ = e2[t3];
}
switch (len - i) {
case 0:
break;
case 1:
t1 = str[i];
*p++ = e0[t1];
*p++ = e1[(t1 & 0x03) << 4];
*p++ = CHARPAD;
*p++ = CHARPAD;
break;
default: /* case 2 */
t1 = str[i];
t2 = str[i + 1];
*p++ = e0[t1];
*p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
*p++ = e2[(t2 & 0x0F) << 2];
*p++ = CHARPAD;
}
*p = '\0';
return p - (uint8_t *) dest;
}
#ifdef WORDS_BIGENDIAN /* BIG ENDIAN -- SUN / IBM / MOTOROLA */
int modp_b64_decode(char* dest, const char* src, int len)
{
if (len == 0) return 0;
#ifdef DOPAD
/* if padding is used, then the message must be at least
4 chars and be a multiple of 4.
there can be at most 2 pad chars at the end */
if (len < 4 || (len % 4 != 0)) return -1;
if (src[len-1] == CHARPAD) {
len--;
if (src[len -1] == CHARPAD) {
len--;
}
}
#endif /* DOPAD */
int i;
int leftover = len % 4;
int chunks = (leftover == 0) ? len / 4 - 1 : len /4;
uint8_t* p = (uint8_t*) dest;
uint32_t x = 0;
uint32_t* destInt = (uint32_t*) p;
uint32_t* srcInt = (uint32_t*) src;
uint32_t y = *srcInt++;
for (i = 0; i < chunks; ++i) {
x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] |
d2[y >> 8 & 0xff] | d3[y & 0xff];
if (x >= BADCHAR) return -1;
*destInt = x << 8;
p += 3;
destInt = (uint32_t*)p;
y = *srcInt++;
}
switch (leftover) {
case 0:
x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] |
d2[y >> 8 & 0xff] | d3[y & 0xff];
if (x >= BADCHAR) return -1;
*p++ = ((uint8_t*)&x)[1];
*p++ = ((uint8_t*)&x)[2];
*p = ((uint8_t*)&x)[3];
return (chunks+1)*3;
case 1:
x = d3[y >> 24];
*p = (uint8_t)x;
break;
case 2:
x = d3[y >> 24] *64 + d3[(y >> 16) & 0xff];
*p = (uint8_t)(x >> 4);
break;
default: /* case 3 */
x = (d3[y >> 24] *64 + d3[(y >> 16) & 0xff])*64 +
d3[(y >> 8) & 0xff];
*p++ = (uint8_t) (x >> 10);
*p = (uint8_t) (x >> 2);
break;
}
if (x >= BADCHAR) return -1;
return 3*chunks + (6*leftover)/8;
}
#else /* LITTLE ENDIAN -- INTEL AND FRIENDS */
int modp_b64_decode(char *dest, const char *src, int len) {
if (len == 0) return 0;
#ifdef DOPAD
/*
* if padding is used, then the message must be at least
* 4 chars and be a multiple of 4
*/
if (len < 4 || (len % 4 != 0)) return -1; /* error */
/* there can be at most 2 pad chars at the end */
if (src[len - 1] == CHARPAD) {
len--;
if (src[len - 1] == CHARPAD) {
len--;
}
}
#endif
int i;
int leftover = len % 4;
int chunks = (leftover == 0) ? len / 4 - 1 : len / 4;
uint8_t *p = (uint8_t *) dest;
uint32_t x = 0;
uint32_t *destInt = (uint32_t *) p;
uint32_t *srcInt = (uint32_t *) src;
uint32_t y = *srcInt++;
for (i = 0; i < chunks; ++i) {
x = d0[y & 0xff] |
d1[(y >> 8) & 0xff] |
d2[(y >> 16) & 0xff] |
d3[(y >> 24) & 0xff];
if (x >= BADCHAR) return -1;
*destInt = x;
p += 3;
destInt = (uint32_t *) p;
y = *srcInt++;
}
switch (leftover) {
case 0:
x = d0[y & 0xff] |
d1[(y >> 8) & 0xff] |
d2[(y >> 16) & 0xff] |
d3[(y >> 24) & 0xff];
if (x >= BADCHAR) return -1;
*p++ = ((uint8_t *) (&x))[0];
*p++ = ((uint8_t *) (&x))[1];
*p = ((uint8_t *) (&x))[2];
return (chunks + 1) * 3;
break;
case 1: /* with padding this is an impossible case */
x = d0[y & 0xff];
*p = *((uint8_t *) (&x)); // i.e. first char/byte in int
break;
case 2: // * case 2, 1 output byte */
x = d0[y & 0xff] | d1[y >> 8 & 0xff];
*p = *((uint8_t *) (&x)); // i.e. first char
break;
default: /* case 3, 2 output bytes */
x = d0[y & 0xff] |
d1[y >> 8 & 0xff] |
d2[y >> 16 & 0xff]; /* 0x3c */
*p++ = ((uint8_t *) (&x))[0];
*p = ((uint8_t *) (&x))[1];
break;
}
if (x >= BADCHAR) return -1;
return 3 * chunks + (6 * leftover) / 8;
}
#endif /* if bigendian / else / endif */
/**
* \file
* <PRE>
* High performance base64 encoder / decoder
* Version 1.3 -- 17-Mar-2006
*
* Copyright &copy; 2005, 2006, Nick Galbreath -- nickg [at] modp [dot] com
* All rights reserved.
*
* http://modp.com/release/base64
*
* Released under bsd license. See modp_b64.c for details.
* </pre>
*
* The default implementation is the standard b64 encoding with padding.
* It's easy to change this to use "URL safe" characters and to remove
* padding. See the modp_b64.c source code for details.
*
*/
#ifndef MODP_B64
#define MODP_B64
#ifdef __cplusplus
extern "C" {
#endif
/**
* Encode a raw binary string into base 64.
* src contains the bytes
* len contains the number of bytes in the src
* dest should be allocated by the caller to contain
* at least modp_b64_encode_len(len) bytes (see below)
* This will contain the null-terminated b64 encoded result
* returns length of the destination string plus the ending null byte
* i.e. the result will be equal to strlen(dest) + 1
*
* Example
*
* \code
* char* src = ...;
* int srclen = ...; //the length of number of bytes in src
* char* dest = (char*) malloc(modp_b64_encode_len);
* int len = modp_b64_encode(dest, src, sourcelen);
* if (len == -1) {
* printf("Error\n");
* } else {
* printf("b64 = %s\n", dest);
* }
* \endcode
*
*/
int modp_b64_encode(char *dest, const char *str, int len);
/**
* Decode a base64 encoded string
*
* src should contain exactly len bytes of b64 characters.
* if src contains -any- non-base characters (such as white
* space, -1 is returned.
*
* dest should be allocated by the caller to contain at least
* len * 3 / 4 bytes.
*
* Returns the length (strlen) of the output, or -1 if unable to
* decode
*
* \code
* char* src = ...;
* int srclen = ...; // or if you don't know use strlen(src)
* char* dest = (char*) malloc(modp_b64_decode_len(srclen));
* int len = modp_b64_decode(dest, src, sourcelen);
* if (len == -1) { error }
* \endcode
*/
int modp_b64_decode(char *dest, const char *src, int len);
/**
* Given a source string of length len, this returns the amount of
* memory the destination string should have.
*
* remember, this is integer math
* 3 bytes turn into 4 chars
* ceiling[len / 3] * 4 + 1
*
* +1 is for any extra null.
*/
#define modp_b64_encode_len(A) ((A+2)/3 * 4 + 1)
/**
* Given a base64 string of length len,
* this returns the amount of memory required for output string
* It maybe be more than the actual number of bytes written.
* NOTE: remember this is integer math
* this allocates a bit more memory than traditional versions of b64
* decode 4 chars turn into 3 bytes
* floor[len * 3/4] + 2
*/
#define modp_b64_decode_len(A) (A / 4 * 3 + 2)
/**
* Will return the strlen of the output from encoding.
* This may be less than the required number of bytes allocated.
*
* This allows you to 'deserialized' a struct
* \code
* char* b64encoded = "...";
* int len = strlen(b64encoded);
*
* struct datastuff foo;
* if (modp_b64_encode_strlen(sizeof(struct datastuff)) != len) {
* // wrong size
* return false;
* } else {
* // safe to do;
* if (modp_b64_decode((char*) &foo, b64encoded, len) == -1) {
* // bad characters
* return false;
* }
* }
* // foo is filled out now
* \endcode
*/
#define modp_b64_encode_strlen(A) ((A + 2)/ 3 * 4)
#ifdef __cplusplus
}
#include <string>
inline std::string &modp_b64_encode(std::string &s) {
std::string x(modp_b64_encode_len(s.size()), '\0');
int d = modp_b64_encode(const_cast<char *>(x.data()), s.data(), s.size());
x.erase(d, std::string::npos);
s.swap(x);
return s;
}
/**
* base 64 decode a string (self-modifing)
* On failure, the string is empty.
*
* This function is for C++ only (duh)
*
* \param[in,out] s the string to be decoded
* \return a reference to the input string
*/
inline std::string &modp_b64_decode(std::string &s) {
std::string x(modp_b64_decode_len(s.size()), '\0');
int d = modp_b64_decode(const_cast<char *>(x.data()), s.data(), s.size());
if (d < 0) {
x.clear();
} else {
x.erase(d, std::string::npos);
}
s.swap(x);
return s;
}
#endif /* __cplusplus */
#endif /* MODP_B64 */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 WEEXCORE_BASE_ANDROID_ANDROID_JNI_H_
#define WEEXCORE_BASE_ANDROID_ANDROID_JNI_H_
#include <cstdint>
#include <jni.h>
#include "scoped_java_ref.h"
namespace base {
namespace android {
void InitVM(JavaVM *vm);
JNIEnv *AttachCurrentThread();
void DetachFromVM();
ScopedLocalJavaRef<jclass> GetClass(JNIEnv *env, const char *class_name);
jclass GetClass(JNIEnv *env, const char *class_name, intptr_t *class_id);
enum MethodType {
STATIC_METHOD,
INSTANCE_METHOD,
};
jmethodID GetMethod(JNIEnv *env, jclass clazz,
MethodType type, const char *method_name, const char *jni_signature);
jmethodID GetMethod(JNIEnv *env, jclass clazz,
MethodType type, const char *method_name,
const char *jni_signature, intptr_t *method_id);
bool HasException(JNIEnv *env);
bool ClearException(JNIEnv *env);
void CheckException(JNIEnv *env);
} // namespace android
} // namespace base
#endif // WEEXCORE_BASE_ANDROID_ANDROID_JNI_H_
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
//
// Created by furture on 2018/5/31.
//
#include "jbytearray_ref.h"
namespace WeexCore {
JByteArrayRef::JByteArrayRef(JNIEnv *env, jbyteArray array) {
this->env = env;
this->array = array;
if(array != nullptr){
this->bytes = (char *) env->GetByteArrayElements(array, JNI_FALSE);
}
}
JByteArrayRef::~JByteArrayRef() {
if(array != nullptr){
env->ReleaseByteArrayElements(array, (jbyte*)bytes, 0);
array = nullptr;
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment