+TKCell* TKContainer::addCell(std::string theLocation, std::string theName, std::string type, std::string customScript)
+{
+ TKCell *cell = NULL;
+ bool noScript = false;
+
+ if (type == CELLTYPE_JSBASIC || type.length() == 0)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else if (type == CELLTYPE_IN)
+ {
+ cell = cellFactory(theLocation, theName, type, true);
+ noScript = true;
+ }
+ else if (type == CELLTYPE_OUT)
+ {
+ cell = cellFactory(theLocation, theName, type, true);
+ noScript = true;
+ }
+ else if (type == CELLTYPE_BASICSTORAGE)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode requires type '").append(type).append("' but it's not a supported type.");
+ dnNotifyError("Initialization failed", message);
+ }
+
+ if (cell)
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
+ mCells.insert(TKCellMap::value_type(fqnName, cell));
+ if (cell->isInterface())
+ {
+ mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ }
+ if (!noScript)
+ {
+ cell->setCellCode(mEmptyCellClass,(const void*)customScript.c_str());
+ }
+ else
+ {
+ if (customScript.length()>0)
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode is type '").append(type).append("'. This type doesn't support custom script.");
+ dnNotifyError("Initialization failed",message);
+ }
+ }
+ }
+ else
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(),theName.c_str());
+ std::string message = "Failed to create a cell. ";
+ message += fqnName;
+ message += "\n";
+ message += "Out of memory?";
+ dnNotifyError("Initialization failed", message);
+ }
+
+ return cell;
+}
+
+TKCell* TKContainer::addCell(std::string theLocation, std::string theName, TKCellCode *cellCode, std::string customScript)
+{
+ TKCell *cell = NULL;
+
+ std::string type = cellCode->getCellAPIName();
+
+ if (type == CELLTYPE_JSBASIC)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else if (type == CELLTYPE_BASICSTORAGE)
+ {
+ cell = cellFactory(theLocation, theName, type, false);
+ }
+ else if (type == CELLTYPE_OUT)
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode type '").append(type).append("' doesn't support to have a CellCode class.");
+ dnNotifyError("Initialization failed", message);
+ }
+ else if (type == CELLTYPE_IN)
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode requires type '").append(type).append("' doesn't support to have a CellCode class.");
+ dnNotifyError("Initialization failed", message);
+ }
+ else
+ {
+ std::string message = std::string("Failed to construct cell '").append(theLocation).append("#").append(theName);
+ message.append("'\nThe cellcode requires type '").append(type).append("' but it's not a supported type.");
+ dnNotifyError("Initialization failed",message);
+ }
+
+
+ if (cell)
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(), theName.c_str());
+ mCells.insert(TKCellMap::value_type(fqnName, cell));
+ cell->setCellCode(cellCode,(const void*)customScript.c_str());
+
+ if (cell->isInterface())
+ {
+ mInterfaceCells.insert(TKCellMap::value_type(fqnName, cell));
+ }
+ }
+ else
+ {
+ std::string fqnName = getFQNString(theLocation.c_str(),theName.c_str());
+ std::string message = "Failed to create a cell. ";
+ message += fqnName;
+ message += "\n";
+ message += "Out of memory?";
+ dnNotifyError("Initialization failed", message);
+ }
+
+ return cell;
+}
+
+TKCellCode* TKContainer::addCellCode(std::string theName, std::string theAPIType, std::string code)
+{
+ TKCellCode *cellCode = cellCodeFactory(theName, theAPIType, code);
+
+ if (cellCode)
+ {
+ mCellCodes.insert( std::map<std::string, TKCellCode*>::value_type(theName, cellCode));
+ }
+ return cellCode;
+}
+