Изменения в соответствии с libuv.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/nodeJSProjects@48625 954022d7-b5bf-4e40-9824-e11837661b57
This commit is contained in:
Alexey.Golubev
2013-08-08 08:25:28 +00:00
committed by Alexander.Trofimov
parent 9d788d60a4
commit 8c0f48a960
2 changed files with 168 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include "license.nodehun"
#include "nodehun.hpp"
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
@ -157,7 +158,7 @@ void Nodehun::SpellDictionary::CheckSuggestions(uv_work_t* request) {
spellData->numSuggest = 0;
}
void Nodehun::SpellDictionary::SendSuggestions(uv_work_t* request){
void Nodehun::SpellDictionary::SendSuggestions( uv_work_t* request, int status ){
HandleScope scope;
Nodehun::SpellData* spellData = static_cast<Nodehun::SpellData*>(request->data);
@ -251,7 +252,7 @@ void Nodehun::SpellDictionary::addDictionaryWork(uv_work_t* request){
}
}
void Nodehun::SpellDictionary::addDictionaryFinish(uv_work_t* request){
void Nodehun::SpellDictionary::addDictionaryFinish(uv_work_t* request, int status){
HandleScope scope;
Nodehun::DictData* dictData = static_cast<Nodehun::DictData*>(request->data);
@ -337,7 +338,7 @@ void Nodehun::SpellDictionary::addRemoveWordWork(uv_work_t* request){
wordData->success = status == 0;
}
void Nodehun::SpellDictionary::addRemoveWordFinish(uv_work_t* request){
void Nodehun::SpellDictionary::addRemoveWordFinish(uv_work_t* request, int status){
HandleScope scope;
Nodehun::WordData* wordData = static_cast<Nodehun::WordData*>(request->data);

View File

@ -0,0 +1,164 @@
#include "license.nodehun"
#include <uv.h>
#include <string>
#include <hunspell.hxx>
#include <node.h>
#ifdef _WIN32
#define __SLASH__ "\\"
#else
#define __SLASH__ "/"
#endif
namespace Nodehun {
//
// The folder in which the dictionaries are contained
//
std::string _dictionariesPath;
//
// This is the JS object that binds to hunspell:
// its internal methods are simply proxies to the
// related hunspell methods.
//
class SpellDictionary;
//
// Checks to see if a dictionary exists
// based on whether it exists in the dictionary
// directory.
//
bool dictionaryDirectoryExists(const char *file);
//
// Sets where the dictionaries' folder is.
//
v8::Handle<v8::Value> SetDictionariesPath(const v8::Arguments& args);
//
// This registers all of the correct methods and objects
// with nodeJS.
//
void RegisterModule(v8::Handle<v8::Object> target);
//
// This is a baton for the asynchronous work of adding
// or removing a word from the dictionary object at runtime.
//
struct WordData {
uv_work_t request;
v8::Persistent<v8::Function> callback;
bool removeWord;
bool callbackExists;
bool success;
std::string word;
Hunspell *spellClass;
};
//
// represents a work baton to asynchronously add a new
// new dictionary, during runtime, to the object of
// an existing dictionary.
//
struct DictData {
uv_work_t request;
v8::Persistent<v8::Function> callback;
bool callbackExists;
std::string path;
char * dict;
bool notpath;
bool success;
Hunspell *spellClass;
};
//
// This is a baton for the asynchronous work of allowing
// the hunspell object to process a string to see if it is
// a defined word and/or if not what the correct spelling might be.
//
struct SpellData {
uv_work_t request;
v8::Persistent<v8::Function> callback;
std::string word;
bool multiple;
Hunspell *spellClass;
bool wordCorrect;
char **suggestions;
int numSuggest;
};
}
class Nodehun::SpellDictionary : public node::ObjectWrap {
public:
//
// The function that gets called by JavaScript
// when a new object is being created.
//
static v8::Persistent<v8::FunctionTemplate> constructor;
static void Init(v8::Handle<v8::Object> target);
SpellDictionary(const char *);
SpellDictionary(const char *, const char*);
//
// The destructor has to elimintate it's reference
// to the spellClass object (Hunspell) otherwise
// the object's reference count won't go down to zero.
//
~SpellDictionary(){
if (spellClass != NULL)
delete spellClass;
spellClass = NULL;
};
bool pathsExist;
// The pointer to the Hunspell Object.
Hunspell *spellClass;
protected:
//
// When a new JS object is created
//
static v8::Handle<v8::Value> New(const v8::Arguments& args);
//
// Suggest a singularly correct spelling from a string.
//
static v8::Handle<v8::Value> spellSuggest(const v8::Arguments& args);
//
// Suggest a list of possible spellings from a string.
// Ordered by correctness.
//
static v8::Handle<v8::Value> spellSuggestions(const v8::Arguments& args);
//
// Add a new dictionary to an existing dictionary object at runtime (ephemerally).
//
static v8::Handle<v8::Value> addDictionary(const v8::Arguments& args);
//
// Add a word to a dictionary object at runtime (ephemerally).
//
static v8::Handle<v8::Value> addWord(const v8::Arguments& args);
//
// Remove a word from a dictionary object at runtime (ephemerally).
//
static v8::Handle<v8::Value> removeWord(const v8::Arguments& args);
//
// The work (threaded) functionality to add a new dictionary
// to the current dictionary object.
//
static void addDictionaryWork(uv_work_t* request);
//
// The call back to merge the thread back and return the result
// of a successful addition of a dictionary to the dictionary
// at runtime.
//
static void addDictionaryFinish(uv_work_t* request, int status);
//
// add/remove a word work (threaded) to the dictionary
// object at runtime.
//
static void addRemoveWordWork(uv_work_t* request);
//
// the call back to merge the thread that added/removed
// a word from the dictionary object.
//
static void addRemoveWordFinish(uv_work_t* request, int status);
//
// The work (threaded) to check to see if a given
// string and if not what any possible suggestions might be.
//
static void CheckSuggestions(uv_work_t* request);
//
// The call back to merge the thread that checked for spelling
// suggestions from the dictionary object to return the result
// of the work.
//
static void SendSuggestions(uv_work_t* request, int status);
};