OSDN Git Service

Added alert message function.
authortkawata <takuji.kawata@gmail.com>
Mon, 20 Feb 2012 15:55:52 +0000 (00:55 +0900)
committertkawata <takuji.kawata@gmail.com>
Mon, 20 Feb 2012 15:55:52 +0000 (00:55 +0900)
Improved the initialization process.

Source/DNAlert.cpp [new file with mode: 0644]
Source/DNAlert.h [new file with mode: 0644]
Source/DNAlertImpl.h [new file with mode: 0644]
Source/DNContainerBuilder.cpp
Source/DNContainerBuilder.h
Source/DNEngine.cpp
Source/DNEngine.h
Source/platform/osx/OSXDNAlert.h [new file with mode: 0644]
Source/platform/osx/OSXDNAlert.mm [new file with mode: 0644]
dennco.xcodeproj/project.pbxproj
dennco/AppDelegate.mm

diff --git a/Source/DNAlert.cpp b/Source/DNAlert.cpp
new file mode 100644 (file)
index 0000000..a26cda1
--- /dev/null
@@ -0,0 +1,28 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on 2/20/2012.
+//
+//
+
+#include "DNAlert.h"
+#include "DNAlertImpl.h"
+
+//static
+void DNAlert::show(std::string title, std::string message)
+{
+    DNAlertImpl::show(title, message);
+}
\ No newline at end of file
diff --git a/Source/DNAlert.h b/Source/DNAlert.h
new file mode 100644 (file)
index 0000000..f6da9a7
--- /dev/null
@@ -0,0 +1,32 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on 2/20/2012.
+//
+//
+
+#ifndef dennco_DNAlert_h
+#define dennco_DNAlert_h
+
+#include <string>
+
+class DNAlert
+{
+public:
+    static void show(std::string title, std::string message);
+};
+
+#endif
diff --git a/Source/DNAlertImpl.h b/Source/DNAlertImpl.h
new file mode 100644 (file)
index 0000000..8079753
--- /dev/null
@@ -0,0 +1,32 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on 2/20/2012.
+//
+//
+
+#ifndef dennco_DNAlertImpl_h
+#define dennco_DNAlertImpl_h
+
+#include <string>
+
+class DNAlertImpl
+{
+public:
+    static void show(std::string title, std::string message);
+};
+
+#endif
index 36d73f1..4eb5e6d 100644 (file)
@@ -41,7 +41,7 @@ DNContainerBuilder::~DNContainerBuilder()
     
 }
 
-TKContainer* DNContainerBuilder::buildContainerFromXHTML(const char* docRoot)
+bool DNContainerBuilder::buildContainerFromXHTML(const char* docRoot)
 {
 
     mLock.lock();
@@ -96,7 +96,7 @@ TKContainer* DNContainerBuilder::buildContainerFromXHTML(const char* docRoot)
     
     mLock.unlock();
     
-    return mContainer;
+    return true;
 }
 
 void DNContainerBuilder::parseXHTML(const char *docRoot, const char *path)
index d4f419c..3a85ffb 100644 (file)
@@ -32,7 +32,7 @@ public:
     DNContainerBuilder(TKContainer *container);
     ~DNContainerBuilder();
     
-    TKContainer *buildContainerFromXHTML(const char* docRoot);
+    bool buildContainerFromXHTML(const char* docRoot);
 
 private:
     void        parseXHTML(const char* docRoot, const char *fpath);
index 4e1f028..694afb0 100644 (file)
 #include "TKUICell.h"
 #include "DNTimeKeeper.h"
 #include "DNHTTPServer.h"
+#include "TKJSContainer.h"
+#include "DNContainerBuilder.h"
 #include "DNEngine.h"
+#include "DNAlert.h"
+#include "DNXML.h"
 
-DNEngine::DNEngine(TKContainer *container) :
-mContainer(container),mIsRunning(false),mPortNumber(9080),mHTTPServer(NULL)
+DNEngine::DNEngine(const char *contentPath) :
+mContainer(NULL),mIsRunning(false),mPortNumber(9080),mHTTPServer(NULL),mValid(false)
 {
     mTimeKeeper = new DNTimeKeeper();
+    mContainer = new TKJSContainer();
+    
+    std::string basePath(contentPath);
+    std::string containerRoot = basePath.append("/Container");
+    
+    bool succeeded = false;
+    succeeded = parseSettingFile(contentPath);
+    if (!succeeded)
+    {
+        DNAlert::show("Initialization failed", "failed to parse setting file /property.xml");
+        return;
+    }
+    succeeded = parseContainerFile(containerRoot.c_str());
+    if (!succeeded)
+    {
+        DNAlert::show("Initialization failed", "failed to parse container file");
+        return;
+    }
+    
+    mValid = true;
+}
 
+DNEngine::~DNEngine()
+{
+    mValid = false;
+    
+    if (mContainer)
+    {
+        delete mContainer;
+        mContainer = NULL;
+    }
+        
+    if (mHTTPServer)
+    {
+        delete mHTTPServer;
+        mHTTPServer = NULL;
+    }
+    
+    if (mTimeKeeper)
+    {
+        delete mTimeKeeper;
+        mTimeKeeper = NULL;
+    }
+}
+
+
+bool DNEngine::parseSettingFile(const char *contentRoot)
+{
+    DNXML *xml = DNXML::createXMLFromFile(contentRoot, "property.xml");
+    if (xml)
+    {
+        
+    }
+    return false;
+}
+
+bool DNEngine::parseContainerFile(const char *containerRoot)
+{
+    DNContainerBuilder builder(mContainer);
+    return builder.buildContainerFromXHTML(containerRoot);
 }
 
 
index 5366924..253ce7d 100644 (file)
@@ -31,7 +31,8 @@ class DNHTTPServer;
 class DNEngine
 {
 public:
-    DNEngine(TKContainer *container);
+    DNEngine(const char *contentPath);
+    virtual ~DNEngine();
     
     bool        startHTTPServer(int portNumber);
     void        stopServer();
@@ -44,14 +45,20 @@ public:
 
     std::string getContentPath();
     
+    bool        isValid() { return mValid; }
+    
     
 private:
+    bool            parseSettingFile(const char *settingXML);
+    bool            parseContainerFile(const char *containerRoot);
+    
     TKContainer     *mContainer;
     int             mPortNumber;
     TKLock          mTickThreadLock;
     DNHTTPServer    *mHTTPServer;
     bool            mIsRunning;
     DNTimeKeeper    *mTimeKeeper;
+    bool            mValid;
     
     
 };
diff --git a/Source/platform/osx/OSXDNAlert.h b/Source/platform/osx/OSXDNAlert.h
new file mode 100644 (file)
index 0000000..5eacab0
--- /dev/null
@@ -0,0 +1,24 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on 2/20/2012.
+//
+//
+
+#import <Cocoa/Cocoa.h>
+
+#include "DNAlertImpl.h"
+
diff --git a/Source/platform/osx/OSXDNAlert.mm b/Source/platform/osx/OSXDNAlert.mm
new file mode 100644 (file)
index 0000000..6819efd
--- /dev/null
@@ -0,0 +1,35 @@
+//  Copyright (c) 2012 Dennco Project
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+//
+//  Created by tkawata on 2/20/2012.
+//
+//
+
+#import "OSXDNAlert.h"
+
+#include <string>
+
+//static
+void DNAlertImpl::show(std::string title, std::string message)
+{
+    NSString *nstitle = [[NSString alloc]initWithUTF8String:title.c_str()];
+    NSString *nsmessage = [[NSString alloc]initWithUTF8String:message.c_str()];
+    
+    NSAlert *alert = [NSAlert alertWithMessageText:nstitle
+                                     defaultButton:@"OK" alternateButton:nil otherButton:nil
+                         informativeTextWithFormat:nsmessage];
+    [alert runModal];
+}
index 731f15c..dc41302 100644 (file)
                7F0E779014B48A3200AFE3A5 /* startup22_2.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F0E778214B4749E00AFE3A5 /* startup22_2.js */; };
                7F0E779114B48A3200AFE3A5 /* startup31_2.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F0E778414B474AA00AFE3A5 /* startup31_2.js */; };
                7F0E779214B48A5A00AFE3A5 /* layer1_2.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F0E776714B461F000AFE3A5 /* layer1_2.js */; };
+               7F1C16A214F1C2AB00BF9525 /* DNAlert.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7F1C16A114F1C2AB00BF9525 /* DNAlert.cpp */; };
                7F2FBB9114AC9D9B004F8FBE /* layer1_1.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F2FBB8A14AC9CB0004F8FBE /* layer1_1.js */; };
                7F2FBB9214AC9D9B004F8FBE /* layer2_1.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F2FBB8C14AC9D31004F8FBE /* layer2_1.js */; };
                7F2FBB9314AC9D9B004F8FBE /* layer3_1.js in Resources */ = {isa = PBXBuildFile; fileRef = 7F2FBB8E14AC9D3A004F8FBE /* layer3_1.js */; };
                7F4C432414AE26730098694B /* SourceViewWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7F4C432314AE26730098694B /* SourceViewWindow.xib */; };
                7F4C7A0714D50CCD00BDD697 /* OSXDNSimpleHTTPServerImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7F4C7A0514D50AC400BDD697 /* OSXDNSimpleHTTPServerImpl.mm */; };
                7F4C7A0814D5626800BDD697 /* TKUICell.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7FDCE1C714ACBB68002E3FBF /* TKUICell.cpp */; };
+               7F4C98B414F26A9D00FAFD25 /* OSXDNAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7F4C98B314F26A9D00FAFD25 /* OSXDNAlert.mm */; };
                7FBD330914E95F30001A68DB /* SimpleHTTPConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7FBD330614E95F30001A68DB /* SimpleHTTPConnection.mm */; };
                7FBD330A14E95F30001A68DB /* SimpleHTTPServer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7FBD330814E95F30001A68DB /* SimpleHTTPServer.mm */; };
                7FBD330D14E9D92E001A68DB /* SimpleHTTPServerController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7FBD330C14E9D92E001A68DB /* SimpleHTTPServerController.mm */; };
                7F0E778014B4748800AFE3A5 /* startup21_2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = startup21_2.js; sourceTree = "<group>"; };
                7F0E778214B4749E00AFE3A5 /* startup22_2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = startup22_2.js; sourceTree = "<group>"; };
                7F0E778414B474AA00AFE3A5 /* startup31_2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = startup31_2.js; sourceTree = "<group>"; };
+               7F1C169F14F1C29E00BF9525 /* DNAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNAlert.h; sourceTree = "<group>"; };
+               7F1C16A114F1C2AB00BF9525 /* DNAlert.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DNAlert.cpp; sourceTree = "<group>"; };
                7F2DB0BF14CE25A5008030AC /* DNServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNServer.h; sourceTree = "<group>"; };
                7F2FBB8A14AC9CB0004F8FBE /* layer1_1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = layer1_1.js; sourceTree = "<group>"; };
                7F2FBB8C14AC9D31004F8FBE /* layer2_1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = layer2_1.js; sourceTree = "<group>"; };
                7F4C432314AE26730098694B /* SourceViewWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SourceViewWindow.xib; sourceTree = "<group>"; };
                7F4C7A0414D50AAF00BDD697 /* OSXDNSimpleHTTPServerImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSXDNSimpleHTTPServerImpl.h; sourceTree = "<group>"; };
                7F4C7A0514D50AC400BDD697 /* OSXDNSimpleHTTPServerImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OSXDNSimpleHTTPServerImpl.mm; sourceTree = "<group>"; };
+               7F4C98B014F269AB00FAFD25 /* DNAlertImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNAlertImpl.h; sourceTree = "<group>"; };
+               7F4C98B214F26A9D00FAFD25 /* OSXDNAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSXDNAlert.h; sourceTree = "<group>"; };
+               7F4C98B314F26A9D00FAFD25 /* OSXDNAlert.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OSXDNAlert.mm; sourceTree = "<group>"; };
                7FBD330514E95F30001A68DB /* SimpleHTTPConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleHTTPConnection.h; sourceTree = "<group>"; };
                7FBD330614E95F30001A68DB /* SimpleHTTPConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SimpleHTTPConnection.mm; sourceTree = "<group>"; };
                7FBD330714E95F30001A68DB /* SimpleHTTPServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleHTTPServer.h; sourceTree = "<group>"; };
                                7FCADFD014B8874F0003A23A /* DNXMLElement.h */,
                                7FCADFBF14B860F70003A23A /* DNUtils.cpp */,
                                7FCADFC214B8610B0003A23A /* DNUtils.h */,
+                               7F1C16A114F1C2AB00BF9525 /* DNAlert.cpp */,
+                               7F1C169F14F1C29E00BF9525 /* DNAlert.h */,
+                               7F4C98B014F269AB00FAFD25 /* DNAlertImpl.h */,
                        );
                        path = Source;
                        sourceTree = "<group>";
                                7FCADFD614B8A2C50003A23A /* OSXDNDirectoryImpl.h */,
                                7F4C7A0514D50AC400BDD697 /* OSXDNSimpleHTTPServerImpl.mm */,
                                7F4C7A0414D50AAF00BDD697 /* OSXDNSimpleHTTPServerImpl.h */,
+                               7F4C98B314F26A9D00FAFD25 /* OSXDNAlert.mm */,
+                               7F4C98B214F26A9D00FAFD25 /* OSXDNAlert.h */,
                        );
                        path = osx;
                        sourceTree = "<group>";
                                7FBD330914E95F30001A68DB /* SimpleHTTPConnection.mm in Sources */,
                                7FBD330A14E95F30001A68DB /* SimpleHTTPServer.mm in Sources */,
                                7FBD330D14E9D92E001A68DB /* SimpleHTTPServerController.mm in Sources */,
+                               7F1C16A214F1C2AB00BF9525 /* DNAlert.cpp in Sources */,
+                               7F4C98B414F26A9D00FAFD25 /* OSXDNAlert.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 086939b..679a987 100644 (file)
@@ -11,6 +11,7 @@
 #include "DNDirectory.h"
 #include "DNFileList.h"
 #include "TKLog.h"
+#include "DNAlert.h"
 
 #import "AppDelegate.h"
 
 
 -(IBAction)doInit:(id)sender
 {
-    
-    if (container)
-    {
-        delete container;
-    }
-    container = new TKJSContainer();
-    
-    DNContainerBuilder builder(container);
-  
-    const char *path = [[[uiPathControl URL]path] UTF8String];
-    builder.buildContainerFromXHTML(path);
-    
-    
+    engine = new DNEngine([[[uiPathControl URL]path] UTF8String]);
 }
 
 -(IBAction)doStart:(id)sender
 {
-    engine = new DNEngine(container);
-    engine->setTickIntervalSec(1.0);
-    engine->startHTTPServer(9080);
+    if (engine && engine->isValid())
+    {
+        engine->setTickIntervalSec(1.0);
+        engine->startHTTPServer(9080);
+    }
 }
 
 -(IBAction)doStop:(id)sender