Skip to content

Commit

Permalink
Added Embedded Woopsa, an ultralightweight C library!
Browse files Browse the repository at this point in the history
- [Feature] WoopsaEmbedded has been added, which supports meta/read/write/Invoke
- [Feature] A sample server which builds on Windows / Linux using embedded Woopsa
- [Bug] Corrected too many slashes problem for invoke on C# client

To come soon: an Arduino demo
  • Loading branch information
floriansegginger committed Nov 20, 2015
1 parent 4397cb5 commit 4f7181a
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 139 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Debug
*.suo
*.filters
*.user
*.log
*.log
/Sources/Embedded/Release
Binary file modified Release/DotNet/Woopsa.dll
Binary file not shown.
Binary file modified Release/DotNet/Woopsa.pdb
Binary file not shown.
Binary file modified Release/DotNet/WoopsaDemoClient.exe
Binary file not shown.
Binary file modified Release/DotNet/WoopsaDemoServer.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Sources/DotNet/Woopsa/Client/WoopsaClientObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private WoopsaValue Invoke(IEnumerable<IWoopsaValue> arguments, List<WoopsaMetho
{
namedArguments.Add(argumentInfos[i].Name, arguments.ElementAt(i).AsText);
}
return _client.Invoke(this.GetPath() + WoopsaConst.WoopsaPathSeparator + methodName, namedArguments);
return _client.Invoke(this.GetPath().TrimEnd(WoopsaConst.WoopsaPathSeparator) + WoopsaConst.WoopsaPathSeparator + methodName, namedArguments);
}

private WoopsaBaseClient _client = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,29 @@ int sockClose(SOCKET sock) {
return status;
}

int lol = 2;
char lol2[] = "Ha \" ha ha";
float Temperature = 24.2;
char IsRaining = 1;
int Altitude = 430;
float Sensitivity = 0.5;
char City[20] = "Geneva";
float TimeSinceLastRain = 11;


char weatherBuffer[20];
char* GetWeather() {
sprintf(weatherBuffer, "sunny");
return weatherBuffer;
}

WOOPSA_BEGIN(woopsaEntries)
WOOPSA_PROPERTY(lol, WOOPSA_TYPE_INTEGER)
WOOPSA_PROPERTY(lol2, WOOPSA_TYPE_TEXT)
WOOPSA_END
WOOPSA_PROPERTY_READONLY(Temperature, WOOPSA_TYPE_REAL)
WOOPSA_PROPERTY(IsRaining, WOOPSA_TYPE_LOGICAL)
WOOPSA_PROPERTY(Altitude, WOOPSA_TYPE_INTEGER)
WOOPSA_PROPERTY(Sensitivity, WOOPSA_TYPE_REAL)
WOOPSA_PROPERTY(City, WOOPSA_TYPE_TEXT)
WOOPSA_PROPERTY(TimeSinceLastRain, WOOPSA_TYPE_TIME_SPAN)
WOOPSA_METHOD(GetWeather, WOOPSA_TYPE_TEXT)
WOOPSA_END;

#define WOOPSA_PORT 8000
#define BUFFER_SIZE 1024
Expand All @@ -72,12 +88,12 @@ int main(int argc, char argv[]) {
SOCKET sock, clientSock;
struct sockaddr_in addr, clientAddr;
char buffer[BUFFER_SIZE];
int clientAddrSize, readBytes;
int clientAddrSize = 0, readBytes = 0;
WoopsaServer server;
WoopsaUInt16 responseLength;

memset(buffer, 0, sizeof(buffer));
WoopsaServerInit(&server, "/woopsa/", woopsaEntries);
WoopsaServerInit(&server, "/woopsa/", woopsaEntries, NULL);

printf("Woopsa C library v0.1 demo server.\n");

Expand Down Expand Up @@ -113,20 +129,29 @@ int main(int argc, char argv[]) {
}

while (1) {
readBytes = recv(clientSock, buffer, sizeof(buffer), NULL);
readBytes = recv(clientSock, buffer + readBytes, sizeof(buffer), NULL);

if (readBytes == SOCKET_ERROR) {
printf("Error %d", WSAGetLastError());
break;
}

if (readBytes == 0) {
printf("Finished\n");
break;
}

if (WoopsaCheckRequestComplete(buffer, sizeof(buffer)) != 1) {
if (WoopsaCheckRequestComplete(&server, buffer, sizeof(buffer)) != 1) {
// If the request is not complete, it means more data needs
// to be -added- to the buffer
continue;
}

if (WoopsaHandleRequest(&server, buffer, sizeof(buffer), buffer, sizeof(buffer), &responseLength) >= WOOPSA_SUCCESS) {
send(clientSock, buffer, responseLength, NULL);
}
readBytes = 0;
memset(buffer, 0, sizeof(buffer));
}
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Embedded/DemoServer/DemoServer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\Server\woopsa-server.c" />
<ClCompile Include="Server.c" />
<ClCompile Include="DemoServer.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Server\woopsa-server.h" />
Expand Down
2 changes: 1 addition & 1 deletion Sources/Embedded/Server/Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>Makefile</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
Expand Down
41 changes: 39 additions & 2 deletions Sources/Embedded/Server/woopsa-config.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
#ifndef __WOOPSA_CONFIG_H_
#define __WOOPSA_CONFIG_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


// Woopsa uses these internally, allowing you to use Woopsa in a
// thread-safe manner, or disabling interrupts. Just fill this in
// if needed with whatever locking mechanism your environment has.
#define WOOPSA_LOCK
#define WOOPSA_UNLOCK
#define WOOPSA_LOCK // disable interrupts
#define WOOPSA_UNLOCK // enable interrupts

// If you are on a system with very low memory, you can reduce the
// buffer size that the Woopsa server uses internally.
// This value changes the maximum length of URLs you can parse.
// You should not go under 128 bytes to be 100% safe.
#define WOOPSA_BUFFER_SIZE 256

// Thanks microsoft for not supporting snprintf!
#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf
#endif

#define WOOPSA_ENABLE_STRINGS
#define WOOPSA_ENABLE_METHODS

// 99% of systems will have the standard C library but in case
// you end up in the 1%, you can always re-define these functions
// to work for you.
#define WOOPSA_INTEGER_TO_PADDED_STRING(value, string, padding) sprintf(string, "%" #padding "d", value)
#define WOOPSA_INTEGER_TO_STRING(value, string, max_length) snprintf(string, max_length, "%d", value)
#define WOOPSA_REAL_TO_STRING(value, string, max_length) snprintf(string, max_length, "%f", value)

#define WOOPSA_STRING_TO_INTEGER(value, string) (value = atoi(string))
#define WOOPSA_STRING_TO_FLOAT(value, string) (value = atof(string))

#define WOOPSA_STRING_POSITION(haystack, needle) strstr(haystack, needle)
#define WOOPSA_STRING_EQUAL(string1, string2) (strcmp(string1, string2) == 0)
#define WOOPSA_STRING_LENGTH(string) strlen(string)
#define WOOPSA_CHAR_TO_LOWER(character) tolower(character)
#define WOOPSA_STRING_COPY(destination, source) strcpy(destination, source)
#define WOOPSA_STRING_N_COPY(destination, source, n) strncpy(destination, source, n)

#endif
Loading

0 comments on commit 4f7181a

Please sign in to comment.