Skip to content

Commit fe655d8

Browse files
committed
Merge branch 'development' of https://git01.codeplex.com/casablanca into files_in_ide
2 parents 9a3bbd6 + c8f4489 commit fe655d8

6 files changed

Lines changed: 142 additions & 27 deletions

File tree

Build/Common.Build.settings

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
115115
<ClCompile>
116116
<Optimization>Disabled</Optimization>
117-
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
117+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118118
</ClCompile>
119119
<Link>
120120
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -132,7 +132,7 @@
132132

133133
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
134134
<ClCompile>
135-
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
135+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
136136
</ClCompile>
137137
<Link>
138138
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -150,7 +150,7 @@
150150

151151
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
152152
<ClCompile>
153-
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
153+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
154154
</ClCompile>
155155
<Link>
156156
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -159,7 +159,7 @@
159159

160160
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
161161
<ClCompile>
162-
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
162+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
163163
</ClCompile>
164164
<Link>
165165
<GenerateDebugInformation>true</GenerateDebugInformation>

Release/include/pplx/pplxtasks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ namespace Concurrency {
5353

5454
#include "pplx/pplx.h"
5555

56+
#if defined(__ANDROID__)
57+
#include <jni.h>
58+
void cpprest_init(JavaVM*);
59+
#endif
60+
5661
// Cannot build using a compiler that is older than dev10 SP1
5762
#if defined(_MSC_VER)
5863
#if _MSC_FULL_VER < 160040219 /*IFSTRIP=IGN*/

Release/include/pplx/threadpool.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ class threadpool
7272
for (size_t i = 0; i < n; i++)
7373
add_thread();
7474
}
75-
75+
#if defined(__ANDROID__)
76+
static threadpool& shared_instance();
77+
#else
7678
static threadpool& shared_instance()
7779
{
7880
return s_shared;
7981
}
80-
82+
#endif
8183
~threadpool()
8284
{
8385
m_service.stop();
@@ -103,7 +105,9 @@ class threadpool
103105
private:
104106
struct _cancel_thread { };
105107

108+
#if !defined(__ANDROID__)
106109
static threadpool s_shared;
110+
#endif
107111

108112
void add_thread()
109113
{
@@ -128,11 +132,6 @@ class threadpool
128132
static void* thread_start(void *arg)
129133
{
130134
#if (defined(ANDROID) || defined(__ANDROID__))
131-
// Spinlock on the JVM calling JNI_OnLoad()
132-
while (JVM == nullptr)
133-
{
134-
pplx::details::platform::YieldExecution();
135-
}
136135
// Calling get_jvm_env() here forces the thread to be attached.
137136
get_jvm_env();
138137
pthread_cleanup_push(detach_from_java, nullptr);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
<id>cpprestsdk.android</id>
5+
<version>2.3.0.1</version>
6+
<title>C++ REST SDK - Android</title>
7+
<authors>casablancacore</authors>
8+
<owners>Microsoft, Visual C++</owners>
9+
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
10+
<projectUrl>https://casablanca.codeplex.com/</projectUrl>
11+
<iconUrl>https://download-codeplex.sec.s-msft.com/Download?ProjectName=casablanca&amp;DownloadId=630102&amp;Build=20425</iconUrl>
12+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
13+
<summary>The C++ REST SDK is a cross-platform, modern, and asynchronous library that enables developers to access and author connected applications</summary>
14+
<description>This library is a Microsoft effort to support cloud-based client-server communication in native code using a modern asynchronous C++ API design. The C++ REST SDK (codename "Casablanca") is a project to start exploring how to best support C++ developers who want to take advantage of the radical shift in software architecture that cloud computing represents.</description>
15+
<releaseNotes>Release of C++ Rest SDK 2.3.0 libraries for android.</releaseNotes>
16+
<copyright>Copyright 2014</copyright>
17+
<tags>REST, native, C++, JSON, Casablanca, Http, Uri, WebSockets, android</tags>
18+
<dependencies>
19+
<dependency id="boost" version="[1.55, 1.56)" />
20+
<dependency id="boost_atomic-android" version="[1.55, 1.56)" />
21+
<dependency id="boost_chrono-android" version="[1.55, 1.56)" />
22+
<dependency id="boost_date_time-android" version="[1.55, 1.56)" />
23+
<dependency id="boost_filesystem-android" version="[1.55, 1.56)" />
24+
<dependency id="boost_locale-android" version="[1.55, 1.56)" />
25+
<dependency id="boost_system-android" version="[1.55, 1.56)" />
26+
<dependency id="boost_thread-android" version="[1.55, 1.56)" />
27+
<dependency id="openssl-android" version="[1.0.1, 1.0.2)" />
28+
</dependencies>
29+
</metadata>
30+
<files>
31+
<!-- Include header files-->
32+
<file src="..\include\**\*" target="\build\native\include\" />
33+
34+
<!-- clang-3.4 -->
35+
<file src="..\..\Binaries\ARM\Release\cpprest140_android_2_3.a" target="\build\native\lib\arm\libcpprest-clang_3_4-gnustl-2_3.a" />
36+
<file src="..\..\Binaries\ARM\Debug\cpprest140d_android_2_3.a" target="\build\native\lib\arm\libcpprest-clang_3_4-d-gnustl-2_3.a" />
37+
38+
<!-- Including license for WebSocket++ -->
39+
<file src="..\libs\websocketpp\COPYING" target="\license\websocketpp\COPYING" />
40+
41+
<!-- vs targets file -->
42+
<file src="cpprestsdk.android.targets" target="\build\native\cpprestsdk.android.targets"/>
43+
</files>
44+
</package>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<CppRestSDKVersionMajor>2</CppRestSDKVersionMajor>
5+
<CppRestSDKVersionMinor>3</CppRestSDKVersionMinor>
6+
<CppRestSDKVersionRevision>0</CppRestSDKVersionRevision>
7+
<CppRestSDKVersionFileSuffix>$(CppRestSDKVersionMajor)_$(CppRestSDKVersionMinor)</CppRestSDKVersionFileSuffix>
8+
</PropertyGroup>
9+
10+
<ItemDefinitionGroup>
11+
<ClCompile>
12+
<PreprocessorDefinitions>HAS_CPPRESTSDK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
13+
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
14+
</ClCompile>
15+
<Link>
16+
<LibraryDependencies>m;%(LibraryDependencies)</LibraryDependencies>
17+
</Link>
18+
</ItemDefinitionGroup>
19+
20+
<ItemGroup>
21+
<CppRestSDKTargetDependencies Include="boost_atomic_android_PreLink" />
22+
<CppRestSDKTargetDependencies Include="boost_chrono_android_PreLink" />
23+
<CppRestSDKTargetDependencies Include="boost_date_time_android_PreLink" />
24+
<CppRestSDKTargetDependencies Include="boost_filesystem_android_PreLink" />
25+
<CppRestSDKTargetDependencies Include="boost_locale_android_PreLink" />
26+
<CppRestSDKTargetDependencies Include="boost_system_android_PreLink" />
27+
<CppRestSDKTargetDependencies Include="boost_thread_android_PreLink" />
28+
<CppRestSDKTargetDependencies Include="openssl_android_PreLink" />
29+
</ItemGroup>
30+
31+
<Target Name="cpprestsdk_android_PreLink" BeforeTargets="@(CppRestSDKTargetDependencies);Link" DependsOnTargets="$(ComputeLinkInputsTargets)">
32+
<!-- ARM and Clang and GNUSTL and Debug -->
33+
<ItemGroup Condition="'$(Platform)' == 'ARM' And '$(PlatformToolset)' == 'Clang_3_4' And ('$(UseOfStl)' == 'gnustl_shared' Or '$(UseOfStl)' == 'gnustl_static') And '$(UseDebugLibraries)' == 'true'">
34+
<Link Include="$(MSBuildThisFileDirectory)lib\arm\libcpprest-clang_3_4-d-gnustl-$(CppRestSDKVersionFileSuffix).a" />
35+
</ItemGroup>
36+
<!-- ARM and Clang and GNUSTL and Release -->
37+
<ItemGroup Condition="'$(Platform)' == 'ARM' And '$(PlatformToolset)' == 'Clang_3_4' And ('$(UseOfStl)' == 'gnustl_shared' Or '$(UseOfStl)' == 'gnustl_static') And '$(UseDebugLibraries)' != 'true'">
38+
<Link Include="$(MSBuildThisFileDirectory)lib\arm\libcpprest-clang_3_4-gnustl-$(CppRestSDKVersionFileSuffix).a" />
39+
</ItemGroup>
40+
41+
<Error
42+
Condition="'$(PlatformToolset)' != 'Clang_3_4'"
43+
Text="The cpprestsdk.android NuGet package only contains binaries for Clang 3.4."
44+
/>
45+
<Error
46+
Condition="'$(UseOfStl)' != 'gnustl_shared' And '$(UseOfStl)' != 'gnustl_static'"
47+
Text="cpprestsdk requires linking against the gnustl. Please set Project Properties -> Configuration Properties -> General -> Use of STL to be 'gnustl_static'."
48+
/>
49+
<Error
50+
Condition="'$(Platform)' != 'ARM'"
51+
Text="The cpprestsdk.android NuGet package only contains binaries for the ARM architecture."
52+
/>
53+
</Target>
54+
</Project>

Release/src/pplx/threadpool.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,29 @@
1818
**/
1919
#include "stdafx.h"
2020

21+
#if defined(__ANDROID__)
22+
#include <android/log.h>
23+
#include <jni.h>
24+
#endif
25+
2126
namespace crossplat
2227
{
23-
// initialize the static shared threadpool
24-
threadpool threadpool::s_shared(40);
25-
2628
#if (defined(ANDROID) || defined(__ANDROID__))
2729
// This pointer will be 0-initialized by default (at load time).
2830
std::atomic<JavaVM*> JVM;
2931

30-
JNIEnv* get_jvm_env()
32+
static void abort_if_no_jvm()
3133
{
3234
if (JVM == nullptr)
3335
{
34-
throw std::runtime_error("Could not contact JVM");
36+
__android_log_print(ANDROID_LOG_ERROR, "CPPRESTSDK", "%s", "The CppREST SDK must be initialized before first use on android: https://casablanca.codeplex.com/wikipage?title=Use%20on%20Android");
37+
std::abort();
3538
}
39+
}
40+
41+
JNIEnv* get_jvm_env()
42+
{
43+
abort_if_no_jvm();
3644
JNIEnv* env = nullptr;
3745
auto result = JVM.load()->AttachCurrentThread(&env, nullptr);
3846
if (result != JNI_OK)
@@ -43,20 +51,25 @@ JNIEnv* get_jvm_env()
4351
return env;
4452
}
4553

54+
threadpool& threadpool::shared_instance()
55+
{
56+
abort_if_no_jvm();
57+
static threadpool s_shared(40);
58+
return s_shared;
59+
}
60+
61+
#else
62+
63+
// initialize the static shared threadpool
64+
threadpool threadpool::s_shared(40);
65+
4666
#endif
4767

4868
}
4969

50-
#if (defined(ANDROID) || defined(__ANDROID__))
51-
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
52-
{
53-
JNIEnv* env;
54-
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
55-
{
56-
return -1;
57-
}
58-
59-
crossplat::JVM = vm;
60-
return JNI_VERSION_1_6;
70+
#if defined(__ANDROID__)
71+
void cpprest_init(JavaVM* vm) {
72+
crossplat::JVM = vm;
6173
}
6274
#endif
75+

0 commit comments

Comments
 (0)