I want to write a module that serves a huge virtual .wav file (also plan to add a virtual .ogg file in the future).
I know the size of the file (2Gb) and its fake modification time (2000-01-01 0:00:00) and I have a function to read portion of the file:
void virtwav_read(void *buf, ssize_t bufsz, uint32_t virtofs);
I want to hook the low-level file operations like stat, read, seek, etc. The standard apache code should take care of parsing the headers (including range requests, cache-related stuff) and generate Content-Type, Content-Length, ETag, Last-Modified, etc.
Parsing the request_rec.range is not a big deal. What worries me more is sending the right cache-related headers and HTTP 206 and 304 when approprate. I'm sure apache would do that better than my code.
I thought that setting request_rec.mtime and request_rec.clength would do the trick, but they don't seem to be output fields.
Lastly, VFS is surprisingly unpopular topic. I found only one ancient project http://apvfs.sourceforge.net/ dated 2003.
Here's my minimal module and its config. The right Content-Type is added by apache, but no ETag
LoadModule virtwav_module modules/mod_virtwav.so
AddHandler virtwav-handler .wav
_
#include "apr_hash.h"
#include "ap_config.h"
#include "ap_provider.h"
#include "httpd.h"
#include "http_core.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
#include <unistd.h> /* for sleep() */
static int example_handler(request_rec *r)
{
if (!r->handler || strcmp(r->handler, "virtwav-handler")) return (DECLINED);
//r->clength = 42;
//r->mtime = apr_time_now();
ap_rprintf(r, "clength: %" APR_INT64_T_FMT "\n", (apr_int64_t)r->clength);
ap_rprintf(r, "mtime: %" APR_INT64_T_FMT "\n", (apr_int64_t)r->mtime);
ap_rwrite("dummy", 5, r);
ap_rflush(r);
sleep(50);
return OK;
}
static void register_hooks(apr_pool_t *pool)
{
/* Create a hook in the request handler, so we get called when a request arrives */
ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST);
// ap_hook_dirwalk_stat ?
// This hook allows modules to handle/emulate the apr_stat()
// ap_hook_map_to_storage ?
// This hook allow modules to set the per_dir_config based on their own
}
module AP_MODULE_DECLARE_DATA virtwav_module =
{
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks /* Our hook registering function */
};
Related
I would like to know the proper procedure for calling a .dll file with also having a .cpp and .h files for a certain application. I have a program which is the .cpp file with different .h header files and I also included the .dll file into the folder where the .cpp and .h files are located. I would like to know in the .cpp code how am I able to call upon this .dll file since inside of it there are different functions that will allow a DDC264 Evaluation Board to read data from memory through usb and extract the data. I am using a program called DevC++ and I am receiving a current Error which is [Id] returned 1 exit status and MakefileWin has changed.
Attached below is a snippit of the .cpp code:
I also would like to know how to fix both of these errors .enter image description hereenter image description here
// USB_IO_for_VB6.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "USB_IO_For_VB6.h"
#include "CyAPI.h"
#include <cstring>
#include <malloc.h>
#include "BASETSD.H"
#include <math.h>
#include <stdio.h>
// #include <string.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported variable
//int USB_IO_FOR_VB6_EXPORTS int USB_IO_for_VB6_API =22;
I
USB_IO_FOR_VB6_API int nUSB_IO_for_VB6 = 22;
#define STRINGLEN 65536 //the larger this number is, the faster the data is shifted in.
#define MAX_CHANNELS_FAST 4096 // 2048= 1024A + 1024B
#define DBP 0 //debug print - 1 enables writing some information to a file in "C:\temp\"
// This function reads the device descriptors from the Cypress USB Chip(s).
// It returns arrays of values, one set of values per device detected.
// The user can then use the visual basic software to select which device to use.
int __stdcall ReadDeviceDescriptors(int *USBdevCount, int *bLengthPass, int *bDescriptorTypePass,
long *bcdUSBPass, int *bDeviceClassPass, int *bDeviceSubClassPass,
int *bDeviceProtocolPass, int *bMaxPacketSize0Pass, long *idVendorPass,
long *idProductPass, long *bcdDevicePass, int *iManufacturerPass,
int *iProductPass, int *iSerialNumberPass, int *bNumConfigurationsPass)
{
CCyUSBDevice *USBDevice;
USB_DEVICE_DESCRIPTOR descr;
USBDevice = new CCyUSBDevice(NULL); // Create an instance of CCyUSBDevice
USBdevCount[0] = USBDevice->DeviceCount();
for (int i=0; i < USBDevice->DeviceCount(); i++)
{
if (USBDevice->Open(i))
{
USBDevice->GetDeviceDescriptor(&descr);
bLengthPass[i]=descr.bLength;
bDescriptorTypePass[i]=descr.bDescriptorType;
bcdUSBPass[i]=descr.bcdUSB;
bDeviceClassPass[i]=descr.bDeviceClass;
bDeviceSubClassPass[i]=descr.bDeviceSubClass;
bDeviceProtocolPass[i]=descr.bDeviceProtocol;
bMaxPacketSize0Pass[i]=descr.bMaxPacketSize0;
idVendorPass[i]=descr.idVendor;
idProductPass[i]=descr.idProduct;
bcdDevicePass[i]=descr.bcdDevice;
iManufacturerPass[i]=descr.iManufacturer;
iProductPass[i]=descr.iProduct;
iSerialNumberPass[i]=descr.iSerialNumber;
bNumConfigurationsPass[i]=descr.bNumConfigurations;
USBDevice->Close();
}
}
return( USBdevCount[0] );
}
I am not sure about how to go about calling a .dll file in C++, I am fairly new to Object Oriented programming.
Regarding the MakefileWin error I tried changing the TDM-GCC release version from 32 to 64 bits and the error continues.
I also tried deleting the dllmain.cpp which is another cpp file that is not needed and moving another original.cpp file from the folder that is shown in one of the images.
I only have a single .cpp file running on my DevC++ compiler which I thought would not cause the Error [Id] returned 1 to exit status to pop up.
Im trying to create a program which will interrupt when I press the button. I have Atmega8 and I use Microchip studio for coding.
I checked the document about interrupts on atmega's website however I can't say I totally got it.
Here is my code:
#define F_CPU 1000000UL
#define IRQ1 INT0_vect
#define IRQ2 INT1_vect
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
void init()
{
DDRB=0b11111111;
PORTB=255;
_delay_ms(2000);
PORTB=0;
DDRD = 0b00000000;
GICR=0xc0;
MCUCR=0x08;
}
int main(void){
init();
volatile int mode = 0;
ISR(IRQ1){
_delay_ms(500);
if (mode<3)mode++; else mode = 0;
}
ISR(IRQ2){
_delay_ms(150);
}
}
Errors I get:
Imgur
I would be glad if any admin edits my question and add picture here, website doesn't let me add photo because I need at least 10 reputation to post image
Don't try to define functions inside of other functions unless you really know what you are doing. You should move the ISR definitions to the top level of the file, putting them outside of main.
How can I change state of the camera flash throgh JNI function? I am looking to be able to have ON/OFF state control, just like in Java CameraManager.setTorchMode(cameraId, state); method. I've tried to search for it in native camera API ,but no success. Here's what I have done so far:
#include <jni.h>
#include <assert.h>
#include <jni.h>
#include <pthread.h>
#include <android/native_window_jni.h>
#include <camera/NdkCameraDevice.h>
#include <camera/NdkCameraManager.h>
#include <android/asset_manager.h>
#include "messages-internal.h"
JNIEXPORT void JNICALL
Java_com_android_rxjava_flashlightflicker_MainActivity_flasher(JNIEnv *env, jobject instance) {
ACameraIdList *cameraIdList = NULL;
const char *selectedCameraId = NULL;
ACameraManager *cameraManager = ACameraManager_create();
camera_status_t camera_status = ACAMERA_OK;
camera_status = ACameraManager_getCameraIdList(cameraManager, &cameraIdList);
/// Camera status not ok
if (camera_status != ACAMERA_OK) {
LOGE("Camera is bad id: %d \n", camera_status);
return;
}
// There is no camera
if (cameraIdList->numCameras < 1 ) {
LOGE("Camera is not present on the device.");
return;
}
selectedCameraId = cameraIdList->cameraIds[0];
ACameraMetadata *cameraMetedata = NULL;
ACameraManager_getCameraCharacteristics(cameraManager, selectedCameraId, &cameraMetedata);
// ACaptureSessionOutput_create()
}
I also tried to look in asset manager but no success, can anybody experienced with NDK camera give me a hand with it?
Thanks in advance!
This method is only available in Java API. You could access it through JNI, but IMO it would be easier and safer to write a wrapper static method in Java and have this wrapper called from your C++ code.
First off, I have scoured stack overflow and the rest of the web and I am well aware of the following:
1) Global variables are Bad
2) Global variables dependencies between translation units is bad
However, we are using some middleware that is doing the following; and I can not ascertain whether this is dangerous.
// Global_Variable.hpp
#include "Type.hpp" /* this defines the type as a structure, doesn't really matter :) */
extern Type Global_Variable;
// Global_Variable.cpp
#include "Global_Variable.hpp"
Type Global_Variable = { /* init the struct */ };
// Global_Reference.hpp
#include "Type.hpp"
extern Type & Global_Reference;
// Global_Reference.cpp
#include "Global_Reference.hpp"
#include "Global_Variable.hpp"
Type & Global_Reference = Global_Variable; // does this suffer from the SIOF?
// Global_Pointer.hpp
#include "Type.hpp"
extern Type * Global_Pointer
// Global_Reference.cpp
#include "Global_Pointer.hpp"
#include "Global_Variable.hpp"
Type * Global_Variable = &Global_Variable; // does this suffer from the SIOF?
I am worried that Global_Variable and Global_Reference could be initialized to null rather than Global_Variable, can this be the case?
Thanks!
I am currently trying to learn how to create apache filters to work within Jive, and have been trying to start small and work into what I need.
My issue right now is that I cannot seem to get a basic filter to work. I have followed a few different tutorials on creating and installing, as well as searching this site and many others, but I cannot seem to get any results and do not believe my filter is even being used.
Code:
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#include "ap_compat.h"
#include <stdio.h>
static void register_hooks(apr_pool_t *p);
static int test_filter(request_rec *r);
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(test_filter, NULL, NULL, APR_HOOK_MIDDLE);
}
static int test_filter(request_rec *r)
{
FILE *file;
file = fopen("/usr/local/jive/var/logs/filter.log", "a+");
fprintf(file, "In the Filter!\n");
fclose(file);
return OK;
}
module AP_MODULE_DECLARE_DATA test_module =
{
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
I compile and install the filter using:
apxs -c -i -a /mod_test.c
And I can see in the httpd.config file that the module is installed, so I add to the .config:
AddOutputFilter test-module
And finally, I perform a jive-httpd restart. In the end, the file I am trying to write to is never created or appended to. I am at a complete loss as to what to do now before I can move forward.
Running Jive SBS 4.5.4.0, with Apache/2.2.3 Httpd server.
Any help would be appreciated, and I apologize in advance if my formatting is off.