00001
00002 #include "oaDesignDB.h"
00003 #include "oagFpga.h"
00004 #include "oagFpgaObserver.h"
00005 #include "oagFpgaManager.h"
00006
00007 #include "oagFpgaDebug.h"
00008
00009 namespace oagFpga {
00010
00011
00012
00013
00014
00015
00016
00017 Observer::Observer() : oa::oaObserver<oa::oaDesign>(10) {
00018 DEBUG_PRINTLN("initialized observer")
00019 }
00020
00021
00022
00023
00024
00026
00027
00028 void
00029 Observer::onFirstOpen(oa::oaDesign *design) {
00030 if(design->getTopModule()) {
00031 oa::oaString moduleNameString;
00032 design->getTopModule()->getName(oa::oaNativeNS(), moduleNameString);
00033 DEBUG_PRINTLN("open " << moduleNameString)
00034 } else {
00035 DEBUG_PRINTLN("open ")
00036 }
00037
00038 if( !design->getAppDefs().includes(streamAppDef) ) {
00039 DEBUG_PRINTLN("\tno functional description");
00040 return;
00041 }
00042 oa::oaByte *buf = new oa::oaByte[streamAppDef->getSize(design)];
00043 streamAppDef->get(design, buf);
00044 int size = Manager::unserialize(static_cast<void*>(buf), design);
00045 static_cast<void>(size);
00046 DEBUG_PRINTLN("\t" << "serialized design occupied " << size << " bytes")
00047
00048 streamAppDef->destroy(design);
00049 DEBUG_PRINTLN("\t" << "serialized info destroyed")
00050 delete [] buf;
00051 }
00052
00053
00054
00055
00056
00058
00059
00060 void
00061 Observer::onPurge(oa::oaDesign *design) {
00062 if(design->getTopModule()) {
00063 oa::oaString moduleNameString;
00064 design->getTopModule()->getName(oa::oaNativeNS(), moduleNameString);
00065 DEBUG_PRINTLN("purge " << moduleNameString)
00066 } else {
00067 DEBUG_PRINTLN("purge ")
00068 }
00069
00070 Manager::destroy(design);
00071 }
00072
00073
00074
00075
00076
00078
00079
00080 void
00081 Observer::onPreSave(oa::oaDesign *design) {
00082 if(design->getTopModule()) {
00083 oa::oaString moduleNameString;
00084 design->getTopModule()->getName(oa::oaNativeNS(), moduleNameString);
00085 DEBUG_PRINTLN("presave " << moduleNameString)
00086 } else {
00087 DEBUG_PRINTLN("presave ")
00088 }
00089
00090 if(!Manager::hasManager(design) || Manager::get(design)->isStructural()) {
00091 return;
00092 }
00093
00094 int bytes = Manager::getSerializedSize(design);
00095 oa::oaByte *buf = new oa::oaByte[bytes];
00096 Manager::serialize(static_cast<void*>(buf), design);
00097 DEBUG_PRINTLN("\t" << "serialized design occupies " << bytes << " bytes")
00098 streamAppDef->set(design, bytes, buf);
00099 delete [] buf;
00100 }
00101
00102
00103
00104
00105
00107
00108
00109 void
00110 Observer::onPostSave(oa::oaDesign *design) {
00111 if(design->getTopModule()) {
00112 oa::oaString moduleNameString;
00113 design->getTopModule()->getName(oa::oaNativeNS(), moduleNameString);
00114 DEBUG_PRINTLN("postsave " << moduleNameString)
00115 } else {
00116 DEBUG_PRINTLN("postsave ")
00117 }
00118
00119 if(!Manager::hasManager(design)) {
00120 return;
00121 }
00122
00123 streamAppDef->destroy(design);
00124
00125 DEBUG_PRINTLN("\t" << "serialized info destroyed")
00126 }
00127
00128 }