Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions modules/ti.Network/HTTPServerRequestFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ class HTTPRequestHandler : public Poco::Net::HTTPRequestHandler {
};

void HTTPRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) {
// XXX(Josh): The request and response object's lifetime is limited to this functions call.
// If the developer should keep a reference to these around past the callback lifetime and then
// attempts to access it may result in a crash!
ValueList args;
args.push_back(Value::NewObject(new HTTPServerRequest(request)));
args.push_back(Value::NewObject(new HTTPServerResponse(response)));
HTTPServerResponse * resp = new HTTPServerResponse(response);
args.push_back(Value::NewObject(resp));
resp->asyncState = 0;
RunOnMainThread(m_callback, args);
while (resp->asyncState > 0) {
Poco::Thread::sleep(5);
}
}

HTTPServerRequestFactory::HTTPServerRequestFactory(KMethodRef callback)
Expand Down
12 changes: 12 additions & 0 deletions modules/ti.Network/HTTPServerResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ HTTPServerResponse::HTTPServerResponse(Poco::Net::HTTPServerResponse &response)
SetMethod("addCookie",&HTTPServerResponse::AddCookie);
SetMethod("setHeader",&HTTPServerResponse::SetHeader);
SetMethod("write",&HTTPServerResponse::Write);
SetMethod("enableAsync",&HTTPServerResponse::EnableAsync);
}

void HTTPServerResponse::SetStatus(const ValueList& args, KValueRef result)
Expand Down Expand Up @@ -102,6 +103,7 @@ void HTTPServerResponse::SetHeader(const ValueList& args, KValueRef result)
void HTTPServerResponse::Write(const ValueList& args, KValueRef result)
{
std::ostream& ostr = response.send();
asyncState = -1;

if (args.at(0)->IsString())
{
Expand All @@ -123,4 +125,14 @@ void HTTPServerResponse::Write(const ValueList& args, KValueRef result)
}
}

void HTTPServerResponse::EnableAsync(const ValueList& args, KValueRef result)
{
if (asyncState >= 0) {
//int v = args.at(0)->ToInt();
asyncState = 1;
} else {
throw ValueException::FromString("response already written, no async allowed.");
}
}

} // namespace Titanium
3 changes: 2 additions & 1 deletion modules/ti.Network/HTTPServerResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Titanium {
class HTTPServerResponse : public StaticBoundObject {
public:
HTTPServerResponse(Poco::Net::HTTPServerResponse &response);

int asyncState; //0:sync & waiting for response; 1:async & waiting for response; -1: got response
private:
void SetStatus(const ValueList& args, KValueRef result);
void SetReason(const ValueList& args, KValueRef result);
Expand All @@ -35,6 +35,7 @@ class HTTPServerResponse : public StaticBoundObject {
void AddCookie(const ValueList& args, KValueRef result);
void SetHeader(const ValueList& args, KValueRef result);
void Write(const ValueList& args, KValueRef result);
void EnableAsync(const ValueList& args, KValueRef result);

Poco::Net::HTTPServerResponse& response;
};
Expand Down
2 changes: 1 addition & 1 deletion modules/ti.UI/mac/MenuDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "MenuMac.h"

@interface MenuDelegate : NSObject
@interface MenuDelegate : NSObject<NSMenuDelegate>
{
Titanium::MenuMac* menu;
BOOL dirty;
Expand Down
2 changes: 1 addition & 1 deletion modules/ti.UI/mac/NativeWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UserWindowMac;

@class WebViewDelegate;

@interface NativeWindow : NSWindow
@interface NativeWindow : NSWindow<NSWindowDelegate>
{
BOOL canReceiveFocus;
WebView* webView;
Expand Down
2 changes: 1 addition & 1 deletion modules/ti.UI/mac/TitaniumApplicationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "UIMac.h"

@interface TitaniumApplicationDelegate : NSObject
@interface TitaniumApplicationDelegate : NSObject<NSApplicationDelegate>
{
Titanium::UIMac *binding;
}
Expand Down